deno_docker
deno_docker copied to clipboard
Create Alpine/APK package for Deno
Using Deno inside of an Alpine docker image is currently not super easy because you need to manually install it and add it to the path. If there were an Alpine APK package for it, it could be a simple matter of adding the following to your Dockerfile:
RUN apk add deno
This would be incredibly valuable for my team since we use Deno scripts in lots of places where we'd normally use Bash scripts. Since build processes are often complex, require multiple commands, and need to run on different environments, scripts are an ideal way to run them. We absolutely loathe writing Bash scripts, and the sooner we can get Deno into an environment so we can stop defaulting to Bash, the happier we are.
Have you considered using deno's docker image? https://hub.docker.com/r/denoland/deno
Also i believe https://github.com/denoland/deno/issues/3711 should be resolved first
Using the denoland/deno:alpine
image may be an option, but when using this setup to build docker images, it means we also need docker-in-docker. The easiest way to do that is to start with the docker:dind
image and add any additional tooling needed on top of that.
Of course, there may already be a good way to create this setup that I'm not aware of. If there is, providing it on the deno install site would also be awesome. 🙂
Using the
denoland/deno:alpine
image may be an option, but when using this setup to build docker images, it means we also need docker-in-docker. The easiest way to do that is to start with thedocker:dind
image and add any additional tooling needed on top of that.
I was thinking something more like https://github.com/denoland/deno_docker#using-your-own-base-image Though i've never heard of dind
Whoops, I was not aware of that repository! This is definitely a good example to follow (though an APK would still be a welcomed simplification).
In case anyone else runs into this: The methodology on that page works great when using a base image with ubuntu, but I'm not able to get it to work on alpine. Running deno in the container results in errors about missing dependencies.
My dockerfile:
FROM denoland/deno:alpine-1.24.1 AS deno
FROM docker:20.10.17-alpine3.16
RUN apk add libgcc qemu
COPY --from=deno /tini /tini
COPY --from=deno /bin/deno /usr/local/bin/deno
(I also tried deno:bin
and deno:distroless
, no luck there either)
Built container and ran deno within it:
docker buildx build --platform=linux/amd64 . --tag test-deno-alpine
docker run -it --rm --entrypoint=deno --platform=linux/amd64 test-deno-alpine
I get the following errors:
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/local/bin/deno)
Error relocating /usr/local/bin/deno: __isnan: symbol not found
Error relocating /usr/local/bin/deno: __memcpy_chk: symbol not found
Error relocating /usr/local/bin/deno: backtrace: symbol not found
Error relocating /usr/local/bin/deno: backtrace_symbols: symbol not found
Error relocating /usr/local/bin/deno: __vfprintf_chk: symbol not found
Error relocating /usr/local/bin/deno: __vsnprintf_chk: symbol not found
Error relocating /usr/local/bin/deno: __mbrlen: symbol not found
Error relocating /usr/local/bin/deno: strtoll_l: symbol not found
Error relocating /usr/local/bin/deno: strtoull_l: symbol not found
Error relocating /usr/local/bin/deno: __memmove_chk: symbol not found
Error relocating /usr/local/bin/deno: __register_atfork: symbol not found
Error relocating /usr/local/bin/deno: gnu_get_libc_version: symbol not found
Error relocating /usr/local/bin/deno: __res_init: symbol not found
It looks like this is because glibc, and I'm not sure why that's so difficult to get to work properly on alpine. The deno:alpine
image looks like it's using a base image that already has this resolved.
I have moved this to deno_docker
as any solution should be addressed in this repo.
I finally managed to get Deno installed into an existing Alpine image without too much complexity. Piggybacking on the deno:alpine
image did work, there were just more resources that needed to be copied.
Here's what I did:
FROM denoland/deno:alpine-1.24.1 AS deno
FROM docker:20.10.16-dind-alpine3.16 # or whatever alpine base image you want
COPY --from=deno /bin/deno /usr/local/bin/deno
COPY --from=deno /usr/glibc-compat /usr/glibc-compat
COPY --from=deno /lib/* /lib/
COPY --from=deno /lib64/* /lib64/
COPY --from=deno /usr/lib/* /usr/lib/
Now works perfectly when running:
docker buildx build --platform=linux/amd64 . --tag test-deno-alpine
docker run -it --rm --entrypoint=deno --platform=linux/amd64 test-deno-alpine