Skip to content

Cannot mkdir in debug distroless image #419

Closed

Description

@przemolb

Hi all,

I am trying to use distroless images for my work. I know that distroless images don't have a shell so I use the debug version in multi-stage builds. But it fails:
Part of my Dockerfile:

FROM gcr.io/distroless/java:debug
RUN mkdir /opt/myfolder
> docker build -f Dockerfile -t mydocker:0.1 .
Sending build context to Docker daemon  189.5MB
Step 1/12 : FROM gcr.io/distroless/java:debug
 ---> 4949b7bccd46
Step 2/12 : RUN mkdir /opt/myfolder
 ---> Running in aff60bc2937b
OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown

Activity

  1. przemolb commented on Oct 15, 2019

    @przemolb
    Author

    The same happens when I use:
    FROM gcr.io/distroless/base-debian10
    or
    FROM gcr.io/distroless/base-debian10:debug

  2. loosebazooka commented on Oct 15, 2019

    @loosebazooka
    Member

    Yeah so RUN by default use /bin/sh (hardcoded) if you use this syntax (shell form)
    The way to invoke busybox (using exec form) is to do something like

    RUN ["/busybox/sh", "-c", "mkdir /opt/myfolder"]
    

    as described here: https://docs.docker.com/engine/reference/builder/#run

  3. chanseokoh commented on Oct 15, 2019

    @chanseokoh
    Member

    Alternatively RUN ["/busybox/mkdir", "-p", "/opt/myfolder"]. You can think like some common tools (ls, chmod, ...) are under /busybox.

  4. przemolb commented on Oct 16, 2019

    @przemolb
    Author

    So busybox is part of the distroless images ?! I thought it is only language related stuff ...

  5. loosebazooka commented on Oct 16, 2019

    @loosebazooka
    Member

    Sorry if it wasn't clear, but you can only do this in debug.

  6. briandealwis commented on Oct 16, 2019

    @briandealwis
    Member

    Alternatively you can use the SHELL directive:

    FROM gcr.io/distroless/java:debug
    SHELL ["/busybox/sh", "-c"]
    RUN mkdir /opt/myfolder
  7. senfo commented on May 4, 2021

    @senfo

    This doesn't seem to fix it for me. I'm starting with FROM gcr.io/distroless/java:8-nonroot and getting the following error:

    OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "/busybox/sh": stat /busybox/sh: no such file or directory: unknown

  8. loosebazooka commented on May 4, 2021

    @loosebazooka
    Member

    As mentioned a few comments up, you can only use busybox in a debug image.

  9. senfo commented on May 4, 2021

    @senfo

    Grr, I completely overlooked that tidbit. Thank you for the clarification. That cleared things up for me.

  10. florath commented on Jan 18, 2022

    @florath

    For the files: I had the same problem and took me some time to solve it. I really want to stay with the non-debug version.

    It is possible to create an empty directory and then COPY it over into the image, like

    $ mkdir config
    $ cat Dockerfile
    FROM ...
    COPY config/ /config/
    

    The COPY command copies over the complete hierarchy, so it is possible to create a complete set of (empty) directories:

    $ mkdir -p config/app
    $ mkdir -p config/keys
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions