moby: starting container process caused: "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"

Description I have error after running RUN apt -yqq install nginx iputils-ping:

container_linux.go:247: starting container process caused: “exec: \”/bin/sh\“: stat /bin/sh: no such file or directory” ERROR: Service ‘nginx’ failed to build: oci runtime error: <same as above>

But the weird thing is, that when I had Docker installed previously, it never happend (I had Docker, uninstalled it and after some time installed again).

Steps to reproduce the issue:

  1. Run docker-compose build
  2. See error

Dockerfile

FROM ubuntu:16.04

WORKDIR /usr/local/src

RUN apt -yqq update
RUN apt -yqq install nginx iputils-ping

COPY docker/nginx/dev.conf /etc/nginx/conf.d/dev.conf
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf

CMD ["nginx"]

docker-compose.yml

version: "3"
services:
  mariadb:
    image: mariadb
    entrypoint: docker-entrypoint.sh mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --innodb_large_prefix=1 --innodb_file_format=barracuda --innodb_file_format_max=barracuda --innodb_file_per_table=1
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=1
      - MYSQL_ROOT_PASSWORD=
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - "8080:80"
    restart: always
    environment:
      - PMA_HOST=mariadb
    links:
      - mariadb
  php:
    image: php:7.1.1-fpm
    ports:
      - "9000:9000"
    volumes:
      - .:/dogopic
    links:
      - mariadb
  nginx:
    build: .
    ports:
      - "8000:80"
    volumes:
      - .:/dogopic
    links:
      - php

Describe the results you received:

PS E:\dogopic> docker-compose build
mariadb uses an image, skipping
phpmyadmin uses an image, skipping
php uses an image, skipping
Building nginx
Step 1/8 : FROM ubuntu:16.04
 ---> 0ef2e08ed3fa
Step 2/8 : MAINTAINER Olgierd Grzyb <kontakt@olgierd.me>
 ---> Using cache
 ---> d00af82c32f0
Step 3/8 : WORKDIR /usr/local/src
 ---> Using cache
 ---> 0a0135a8020e
Step 4/8 : RUN apt -yqq update
 ---> Running in d5a972b3af0d
container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"
ERROR: Service 'nginx' failed to build: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"

Describe the results you expected: Build containers successfuly.

Output of docker version:

Client:
 Version:      17.03.0-ce
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   60ccb22
 Built:        Thu Feb 23 10:40:59 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.03.0-ce
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 07:52:04 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

Containers: 6
 Running: 0
 Paused: 0
 Stopped: 6
Images: 7
Server Version: 17.03.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 977c511eda0925a723debdc94d09459af49d082a
runc version: a01dafd48bc1c7cc12bdb01206f9fea7dd6feb70
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.12-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934 GiB
Name: moby
ID: XPR4:7B3C:XUDP:VCTK:OOGW:NQJW:A7L3:BSJO:GN6R:KLJU:FKNX:S5V4
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 13
 Goroutines: 28
 System Time: 2017-03-09T18:31:09.1487623Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 19
  • Comments: 19 (4 by maintainers)

Most upvoted comments

You load the image when docker starting up. Just remove and install docker again. Work for me

guys, this error may be related to corrupted images (in my case there was shutdown of a build machine during build process). Subsequent attempt to build lead to this problem. So i fixed this by removing all images (including hidden ones) because i cant rely of them anymore. My save-day command was:

docker rmi -f $(docker images -aq)

!!! be careful - it will remove all your images !!!

Looking at the above, I don’t think there’s a bug at hand, so I’ll close this issue.

There are various reasons why this (or similar errors) can occur; some examples:

Create script.sh

cat <<-'EOF'> script.sh 
#!/bin/sh

echo "hello world"
EOF

Create Dockerfile

cat <<-'EOF'> Dockerfile
FROM busybox
COPY /script.sh /
CMD ["/script.sh"]
EOF

Now trying to build an image from these;

example1 fails, because script.sh is not executable:

$ docker build --no-cache -t example1 .
$ docker run --rm example1
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/script.sh\": permission denied": unknown.
``

example2: change the script to be executable, and build a new image. Now the image works:

```bash
$ chmod +x script.sh
$ docker build --no-cache -t example2 .
$ docker run --rm example2
hello world

example3; gives a “not found” error, even though the file exists, and is executable. This is because it has the wrong line-endinges (DOS/Windows), but Linux gives a cryptic error for that situation;

$ unix2dos script.sh
$ docker build --no-cache -t example3 .
$ docker run --rm example3
standard_init_linux.go:190: exec user process caused "no such file or directory"

Closing this issue, but hope the above helps

@fiantsev Thanks!! This worked for me, but, instead of removing all the images, I used docker images to see the images built today and removed them using docker rmi -f <list_of_image_ids>

The “bent image” clue helped me. I got here from googling the error. Docker had crashed while it was upping a project, and the image it was on apparently got bent when it hung, or when I forced Docker to restart.

Removing the specific image that was corrupted with docker rmi -f <myImageId> was a good start, but the full resolution was to prune after that so it stopped bringing the image back from my local cache. docker system prune

You just made a new issue, fixed it, then closed the issue. Ingenius!

$docker inspect gcr.io/distroless/static-debian11:debug
            "Cmd": null,
            "Entrypoint": [
                "/busybox/sh"
            ]

solution 1:

FROM gcr.io/distroless/static-debian11:debug
SHELL ["/busybox/sh", "-c"]
RUN xxx

solution 2:

RUN ["sh", "-c", "mkdir -p /app \
    && ln -sf /usr/local/bin/etcd* /app/etcd"]

works for me

In case anyone is still running into this issue (as I was)… Apparently sometimes this output can appear when you use single quotes instead of double quotes in an ENTRYPOINT or CMD directive.

For instance, the exact same Dockerfile with ENTRYPOINT ['/path/to/bin'] will produce an error message, but the one with ENTRYPOINT ["/path/to/bin"] will behave as expected, with no issues. For reference, this is the error message I was getting:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown.
ERRO[0000] error waiting for container: context canceled 

Also, if you run docker inspect <your image>, the issue is pretty annoying to spot, as it’s not immediately obvious that the entrypoint command is wrapped in single quotes. See this output from the docker inspect command:

"Entrypoint": [
                "/bin/sh",
                "-c",
                "['/go/bin/app']"
            ],

Notice the single quotes.

I eventually stumbled on this article which helped me tremendously, but only after I had debugged this issue for 3 and a half hours.

It would be really nice for this to be fixed somehow, but I’m not sure where to log a fresh issue.

@fiantsev Thanks!! This worked for me, but, instead of removing all the images, I used docker images to see the images built today and removed them using docker rmi -f <list_of_image_ids>

You sir, are fantastic!