adoublef
adoublef9mo ago

Distroless Docker image fails with `libc.so: cannot open shared object file: No such file`

I am building a 1:1 with a Node project using the same base for a docker image distroless/cc. Both projects use the same external dependency pulled from npm called libsql however the Deno project seems to fail with the following error
libc.so: cannot open shared object file: No such file or directory
libc.so: cannot open shared object file: No such file or directory
I am unsure where to direct this issue as I can see that the container does include a file under /lib/x86_64-linux-gnu directory. Here is my current dockerfile
ARG DENO_VERSION=1.37.2

FROM denoland/deno:${DENO_VERSION} AS build
WORKDIR /app

USER deno

COPY deno.* deps.ts ./
RUN deno cache deps.ts

ADD . .

RUN deno cache cmd/www/main.ts

# ? --------------------------------

# FROM gcr.io/distroless/cc AS final
FROM denoland/deno:distroless-${DENO_VERSION} AS final
WORKDIR /app

COPY --from=build /deno-dir /deno-dir
COPY . .

CMD ["run", "-A", "--unstable", "cmd/www/main.ts"]

EXPOSE 8000
ARG DENO_VERSION=1.37.2

FROM denoland/deno:${DENO_VERSION} AS build
WORKDIR /app

USER deno

COPY deno.* deps.ts ./
RUN deno cache deps.ts

ADD . .

RUN deno cache cmd/www/main.ts

# ? --------------------------------

# FROM gcr.io/distroless/cc AS final
FROM denoland/deno:distroless-${DENO_VERSION} AS final
WORKDIR /app

COPY --from=build /deno-dir /deno-dir
COPY . .

CMD ["run", "-A", "--unstable", "cmd/www/main.ts"]

EXPOSE 8000
Any suggestions?
3 Replies
Deno AI Helper
Deno AI Helper9mo ago
Based on the documentation, it seems like you're trying to build a Docker image for your Deno application using the denoland/deno:distroless-${DENO_VERSION} image as a base. The error message you're seeing suggests that the libc.so shared library file cannot be found. The libc.so file is a standard C library that's used by many programs on Linux, including some Node.js and Deno dependencies. If this file is missing or not found, it can cause errors like the one you're seeing. The denoland/deno:distroless-${DENO_VERSION} image is a minimal image that only includes the Deno runtime and its dependencies. It's possible that this image doesn't include the libc.so file, or that it's located in a different directory than where your application is looking for it. One thing you could try is to use a different base image that includes a more complete set of standard Linux libraries. For example, you could try using the denoland/deno:debian-${DENO_VERSION} image instead. This image is based on Debian, which is a more full-featured Linux distribution. Here's how you could modify your Dockerfile to use this image:
ARG DENO_VERSION=1.37.2

FROM denoland/deno:${DENO_VERSION} AS build
WORKDIR /app

USER deno

COPY deno.* deps.ts ./
RUN deno cache deps.ts

ADD . .

RUN deno cache cmd/www/main.ts

# ? --------------------------------

FROM denoland/deno:debian-${DENO_VERSION} AS final
WORKDIR /app

COPY --from=build /deno-dir /deno-dir
COPY . .

CMD ["run", "-A", "--unstable", "cmd/www/main.ts"]

EXPOSE 8000
ARG DENO_VERSION=1.37.2

FROM denoland/deno:${DENO_VERSION} AS build
WORKDIR /app

USER deno

COPY deno.* deps.ts ./
RUN deno cache deps.ts

ADD . .

RUN deno cache cmd/www/main.ts

# ? --------------------------------

FROM denoland/deno:debian-${DENO_VERSION} AS final
WORKDIR /app

COPY --from=build /deno-dir /deno-dir
COPY . .

CMD ["run", "-A", "--unstable", "cmd/www/main.ts"]

EXPOSE 8000
If this doesn't solve your problem, it might be helpful to provide more information about the libsql dependency that you're using. Is this a native Node.js module that requires compilation? If so, you might need to install additional build tools
adoublef
adoublef9mo ago
Libsql is an npm module correct. I will try the Debian package but would prefer the build on top of a distroless image. I will also check with the libsql maintainers as the node application seemed to build just fine, it's just the deno one with the complications