Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal container based on Alpine Linux #156

Open
odiroot opened this issue Dec 31, 2024 · 15 comments
Open

Minimal container based on Alpine Linux #156

odiroot opened this issue Dec 31, 2024 · 15 comments

Comments

@odiroot
Copy link

odiroot commented Dec 31, 2024

You might find it useful, if not please just close this issue.

I managed to build a very lightweight container starting with an Alpine Linux 3.20 base.
The result

REPOSITORY                                     TAG                 IMAGE ID      CREATED             SIZE
docker.io/odiroot/go-librespot                 0.1.3               e2413272e241  58 seconds ago      38.7 MB

See it published here.

Here's the Dockerfile I used

FROM alpine:3.20 AS build

RUN apk -U --no-cache add \
    git go alsa-lib-dev libogg-dev libvorbis-dev

RUN git clone https://github.com/devgianlu/go-librespot.git

RUN cd go-librespot \
    && go build -v ./cmd/daemon


#####

FROM alpine:3.20

RUN apk -U --no-cache add \
    libpulse avahi libgcc gcompat alsa-lib

COPY --from=build go-librespot/daemon /usr/bin/go-librespot

CMD ["/usr/bin/go-librespot", "--config_dir", "/config"]
@praul
Copy link

praul commented Jan 1, 2025

Tested it and its working great for me. Thanks, this is more elegant than my own dockerfile.

@devgianlu
Copy link
Owner

Have you used any particular flag to run the container? It is not able to talk to ALSA on my setup.

@odiroot
Copy link
Author

odiroot commented Jan 1, 2025

Have you used any particular flag to run the container? It is not able to talk to ALSA on my setup.

My bad, only tested with pulse (well, pipewire).
I could look into the alsa problem.

@odiroot
Copy link
Author

odiroot commented Jan 1, 2025

I also forgot to mention how I run this one.

Minimal compose file would be

services:
  go_librespot
    image: docker.io/odiroot/go-librespot:latest
    network_mode: host
    volumes:
      - "./vol_config:/config"
      - "/home/<your username>/.config/pulse/cookie:/pulse_cookie:ro"
      - "/run/user/<your uid>/pulse/native:/pulse_native"
    environment:
      PULSE_SERVER: "unix:/pulse_native"
      PULSE_COOKIE: "/pulse_cookie"
    userns_mode: keep-id

Naturally <your username> has to be replaced with e.g. whoami and <your uid> with id -u.

Now for running with ALSA I believe this should work:

services:
  go_librespot:
    image: docker.io/odiroot/go-librespot:latest
    network_mode: host
    volumes:
      - "./vol_config:/config"
      - "/usr/share/alsa:/usr/share/alsa:ro"
    devices:
      - "/dev/snd:/dev/snd"
    userns_mode: keep-id

@devgianlu
Copy link
Owner

Can confirm that the PulseAudio setup works, I was not able to get ALSA to work, but nontheless I'll add this to the repo and make official docker images!

@odiroot
Copy link
Author

odiroot commented Jan 1, 2025

Can confirm that the PulseAudio setup works, I was not able to get ALSA to work, but nontheless I'll add this to the repo and make official docker images!

Sorry about the ALSA thing. I also couldn't get it to work but for a completely unrelated reason (config being ignored).
I might need to look into the build step. Could be that not all required libraries are provided.

devgianlu added a commit that referenced this issue Jan 1, 2025
@devgianlu
Copy link
Owner

Could be that not all required libraries are provided.

Build fines for me and on the CI too: https://github.com/devgianlu/go-librespot/actions/runs/12573825057/job/35047226348

I'll leave this open if you think there are possible improvements, feel free to make a PR too!

@odiroot
Copy link
Author

odiroot commented Jan 1, 2025

Hey @devgianlu
Just one small nitpick. You link to your other project's containers in Readme: https://github.com/devgianlu/go-librespot?tab=readme-ov-file#using-docker

@devgianlu
Copy link
Owner

Hey @devgianlu Just one small nitpick. You link to your other project's containers in Readme: https://github.com/devgianlu/go-librespot?tab=readme-ov-file#using-docker

Oops, copy pasted too much, thanks for noticing :^)

@praul
Copy link

praul commented Jan 2, 2025

Have you used any particular flag to run the container? It is not able to talk to ALSA on my setup.

My bad, sorry - I only used it with pipe output which should be the most easy scenario for a docker setup

@marco79cgn
Copy link

marco79cgn commented Jan 15, 2025

I'm trying to build this on a Raspberry Pi 4 (bookworm, linux/arm64/v8) but unfortunately the docker build always quits with an error. Any idea how I could fix this? Btw. I only need the pipe output (like @praul).

docker-build-log.txt

@devgianlu
Copy link
Owner

You can use this Dockerfile or a prebuild image

@marco79cgn
Copy link

marco79cgn commented Jan 15, 2025

You can use this Dockerfile or a prebuild image

I already tried both. The prebuild image doesn't exist for my platform:

[+] Running 0/1
 ⠧ go_librespot Pulling                                                                                                                                                                                       0.7s 
no matching manifest for linux/arm64/v8 in the manifest list entries

Whereas with the original Dockerfile I get this error:

=> ERROR [build 4/7] COPY go.mod go.sum ./                                                                                                                                                                   0.0s
------                                                                                                                                                                                                             
 > [build 4/7] COPY go.mod go.sum ./:
------
Dockerfile:7
--------------------
   5 |     WORKDIR /src
   6 |     
   7 | >>> COPY go.mod go.sum ./
   8 |     RUN go mod download
   9 |     
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 6a128ed5-70b8-4722-9c24-c983371ec2b1::wj4afmmx7c8c21gdw3w30w8wd: "/go.sum": not found

@devgianlu
Copy link
Owner

In order to use the Dockerfile you need to clone the repository and do docker build -t go-librespot . inside of it.

@marco79cgn
Copy link

Thanks, I tried. The repo is cloned, the go compiler is on the classpath but still I get an error in a later step:

------
Dockerfile:11
--------------------
   9 |     
  10 |     COPY . .
  11 | >>> RUN go build -v ./cmd/daemon
  12 |     
  13 |     FROM alpine:3.20
--------------------
ERROR: failed to solve: process "/bin/sh -c go build -v ./cmd/daemon" did not complete successfully: exit code: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants