distroless java docker image error

2019-08-28 03:36发布

问题:

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:

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:

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.



标签: java docker