[GH-ISSUE #156] Minimal container based on Alpine Linux #98

Closed
opened 2026-02-28 14:25:20 +03:00 by kerem · 15 comments
Owner

Originally created by @odiroot on GitHub (Dec 31, 2024).
Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/156

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"]
Originally created by @odiroot on GitHub (Dec 31, 2024). Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/156 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](https://hub.docker.com/repository/docker/odiroot/go-librespot/tags/latest/sha256-abc19caba2772f41f50530dee56f9053d4693929fc699debf8a163d7a75491d3). Here's the Dockerfile I used ```dockerfile 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"] ```
kerem closed this issue 2026-02-28 14:25:20 +03:00
Author
Owner

@praul commented on GitHub (Jan 1, 2025):

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

<!-- gh-comment-id:2566997589 --> @praul commented on GitHub (Jan 1, 2025): Tested it and its working great for me. Thanks, this is more elegant than my own dockerfile.
Author
Owner

@devgianlu commented on GitHub (Jan 1, 2025):

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

<!-- gh-comment-id:2567023492 --> @devgianlu commented on GitHub (Jan 1, 2025): Have you used any particular flag to run the container? It is not able to talk to ALSA on my setup.
Author
Owner

@odiroot commented on GitHub (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.

<!-- gh-comment-id:2567024023 --> @odiroot commented on GitHub (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.
Author
Owner

@odiroot commented on GitHub (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
<!-- gh-comment-id:2567027315 --> @odiroot commented on GitHub (Jan 1, 2025): I also forgot to mention how I run this one. Minimal compose file would be ```yaml 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: ```yaml 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 ```
Author
Owner

@devgianlu commented on GitHub (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!

<!-- gh-comment-id:2567121164 --> @devgianlu commented on GitHub (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!
Author
Owner

@odiroot commented on GitHub (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.

<!-- gh-comment-id:2567121840 --> @odiroot commented on GitHub (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.
Author
Owner

@devgianlu commented on GitHub (Jan 1, 2025):

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!

<!-- gh-comment-id:2567125252 --> @devgianlu commented on GitHub (Jan 1, 2025): > 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!
Author
Owner

@odiroot commented on GitHub (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

<!-- gh-comment-id:2567126259 --> @odiroot commented on GitHub (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
Author
Owner

@devgianlu commented on GitHub (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

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

<!-- gh-comment-id:2567127197 --> @devgianlu commented on GitHub (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 Oops, copy pasted too much, thanks for noticing :^)
Author
Owner

@praul commented on GitHub (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

<!-- gh-comment-id:2567337936 --> @praul commented on GitHub (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
Author
Owner

@marco79cgn commented on GitHub (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

<!-- gh-comment-id:2593572320 --> @marco79cgn commented on GitHub (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](https://github.com/user-attachments/files/18428307/docker-build-log.txt)
Author
Owner

@devgianlu commented on GitHub (Jan 15, 2025):

You can use this Dockerfile or a prebuild image

<!-- gh-comment-id:2593577024 --> @devgianlu commented on GitHub (Jan 15, 2025): You can use [this Dockerfile](https://github.com/devgianlu/go-librespot/blob/master/Dockerfile) or [a prebuild image](https://github.com/devgianlu/go-librespot/pkgs/container/go-librespot)
Author
Owner

@marco79cgn commented on GitHub (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
<!-- gh-comment-id:2593590813 --> @marco79cgn commented on GitHub (Jan 15, 2025): > You can use [this Dockerfile](https://github.com/devgianlu/go-librespot/blob/master/Dockerfile) or [a prebuild image](https://github.com/devgianlu/go-librespot/pkgs/container/go-librespot) 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 ```
Author
Owner

@devgianlu commented on GitHub (Jan 15, 2025):

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

<!-- gh-comment-id:2593606613 --> @devgianlu commented on GitHub (Jan 15, 2025): In order to use the Dockerfile you need to clone the repository and do `docker build -t go-librespot .` inside of it.
Author
Owner

@marco79cgn commented on GitHub (Jan 15, 2025):

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
<!-- gh-comment-id:2593646229 --> @marco79cgn commented on GitHub (Jan 15, 2025): 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-librespot#98
No description provided.