问题
I have been trying to create my own busybox base image.
# ./mkimage.sh -t pensu/busybox busybox-static
+ mkdir -p /var/tmp/docker-mkimage.US3tHy0uBQ/rootfs
+ tar --numeric-owner -caf /var/tmp/docker-mkimage.US3tHy0uBQ/rootfs.tar.xz -C /var/tmp/docker-mkimage.US3tHy0uBQ/rootfs '--transform=s,^./,,' .
+ cat > '/var/tmp/docker-mkimage.US3tHy0uBQ/Dockerfile'
+ rm -rf /var/tmp/docker-mkimage.US3tHy0uBQ/rootfs
+ docker build -t pensu/busybox /var/tmp/docker-mkimage.US3tHy0uBQ
Sending build context to Docker daemon 863.2 kB
Sending build context to Docker daemon
Step 0 : FROM scratch
--->
Step 1 : ADD rootfs.tar.xz /
---> 8eac78bfc9d6
Removing intermediate container ad9bbb8f7536
Successfully built 8eac78bfc9d6
+ rm -rf /var/tmp/docker-mkimage.US3tHy0uBQ
I can see the image is available with my docker repo.
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
pensu/busybox latest 8eac78bfc9d6 7 seconds ago 2.476 MB
But when I try to do docker run, I always get the error:
# docker run -it pensu/busybox /bin/sh
exec: "/bin/sh": stat /bin/sh: no such file or directorytime="2015-04-09T16:03:45+05:30" level="fatal" msg="Error response from daemon: Cannot start container 8fe73b7832193c847d7975175a4be86d1f0b550b6a00b812bd4cdd18fe752468: exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
I am not able to understand why is it giving that error? Am I doing something wrong? How else can I validate that I am creating a correct image that is in working condition?
回答1:
After you create image, check it with:
$ docker inspect $image_name
and check what you have in CMD option. For busy box it should be:
"Cmd": [
"/bin/sh"
]
Maybe you are overwritting CMD option in your ./mkimage.sh
回答2:
I hit this error ("stat /bin/bash: no such file or directory") when running the command:
docker exec -it 80372bc2c41e /bin/bash
The solution was to identify the kind of terminal (or shell) that is available on the container. To do so, I ran:
docker inspect 80372bc2c41e
In the output from that command, I saw:
"Cmd": [
"/bin/sh",
"-c",
"gunicorn -b 0.0.0.0:7082 server.app:app"
],
This tells me that there's a /bin/sh
command available, and I was able to connect with:
docker exec -it 80372bc2c41e /bin/sh
回答3:
This error
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown.
occurs when creating a docker image from base image eg. scratch
. This is because the resulting image does not have a shell to execute the image. If your use:
ENV EXECUTABLE hello
cmd [$EXECUTABLE]
in your docker file, docker uses /bin/sh to parse the input string. and hence the error. Inspecting on the image, your will find:
$docker inspect <image-name>
"Entrypoint": [
"/bin/sh",
"-c",
"[$HM_APP]"
]
This means that the ENTRYPOINT or CMD arguments will be parsed using /bin/sh -c. The solution that worked for me is to parse the command as a JSON array of string e.g.
cmd ["hello"]
and inspecting the image again:
"Entrypoint": [
"hello"
]
This removes the dependence on /bin/sh the docker app can now execute the binary file. Example:
FROM scratch
# Environmental variables
# Copy files
ADD . /
# Home dir
WORKDIR /bin
EXPOSE 8083
ENTRYPOINT ["hospitalms"]
Hope this helps someone in future.
回答4:
Explicitly mention the ubuntu version in the docker file which you are trying to RUN,
FROM ubuntu:14.04
Dont use like FROM ubuntu:Latest
. This resolved my above "Cannot Start Container: stat /bin/sh: no such file or directory" issue
回答5:
You have no shell at /bin/sh? Have you tried docker run -it pensu/busybox /usr/bin/sh
?
来源:https://stackoverflow.com/questions/29535015/error-cannot-start-container-stat-bin-sh-no-such-file-or-directory