Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot Start Container: stat /bin/sh: no such file or directory" [closed]

Tags:

docker

busybox

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?

like image 644
Pensu Avatar asked Apr 09 '15 09:04

Pensu


People also ask

How do I execute a docker container?

To use the docker exec command, you will need a running Docker container. If you don't already have a container, start a test container with the following docker run command: docker run -d --name container-name alpine watch "date >> /var/log/date. log"

How do I remove all images from Docker?

Remove all images All the Docker images on a system can be listed by adding -a to the docker images command. Once you're sure you want to delete them all, you can add the -q flag to pass the image ID to docker rmi : List: docker images -a.

What is docker from scratch?

FROM scratch As of Docker 1.5. 0 (specifically, docker/docker#8827 ), FROM scratch is a no-op in the Dockerfile , and will not create an extra layer in your image (so a previously 2-layer image will be a 1-layer image instead).

How do you prune Docker?

The docker system prune command is a shortcut that prunes images, containers, and networks. Volumes are not pruned by default, and you must specify the --volumes flag for docker system prune to prune volumes. By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag.


2 Answers

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

like image 134
wsl Avatar answered Oct 04 '22 02:10

wsl


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 
like image 43
duhaime Avatar answered Oct 04 '22 03:10

duhaime