3

When I attempt to create a docker image using the distroless java base image, I get the following error when I include any shell command like 'mkdir' , 'chmod' any help on this is really appreciated.

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

1

3 Answers 3

8

distroless provides a debug image that contains a shell so that you can exec into it:

gcr.io/distroless/java:debug

The debug images contain busybox. You can run this image with Docker by:

docker run -it --entrypoint "/busybox/sh" gcr.io/distroless/java:debug

If you would like to build a Java Docker image directly in a Maven or Gradle project using distroless as the base, check out Jib.

2

If you look at the list of things in the distroless base image it just doesn't include a shell, or mkdir, or chmod, or anything else like that. The Java image adds the JVM, and that's it. It's probably not going to be possible to build an image based on that that does much more than COPY in a prebuilt jar and set a CMD to point to it, maybe setting some default ENV variables along the way.

If you need the base tools that are included in a standard Linux distribution, then you want to start from a more featureful base image like the standard openjdk image.

2
  • David,Thanks for the response. Based on my searches on "google" and your answer, looks like the distroless java thing is meant only for toy projects at this time. I cant seem to even set a shell script as the entrypoint using the recommended ENTRYPOINT ["/entrypoint.sh"] and hence I cant set things like JAVA_OPTS and other env vars.
    – consult-kk
    Jun 29, 2018 at 19:08
  • For anyone else who comes across this: github.com/GoogleContainerTools/distroless/issues/168
    – gib
    Aug 1, 2019 at 13:54
1

distroless provides a debug image that contains a shell . In pom or running docker from command prompt :

Steps as below :

Pom Change :

<from>
    <image>gcr.io/distroless/java:11-debug</image>
</from>

docker command:

docker exec -it sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.