Failure starting Docker container. "failed to create shim task: OCI runtime create failed: runc create failed"
Asked Answered
A

9

63

I am new to Ubuntu and new to Docker. I am running a command that was given to me in an explanation of how to start the project. I want to start my Docker containers and they fail with an error.

Some notes:

  • It is a new Ubuntu laptop.
  • I added Docker to have sudo privileges. groups yields docker among the list it responds with.

Here's the command I use to start it: docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build

And it gives:

Step 11/12 : EXPOSE $PORT
 ---> Using cache
 ---> 7620427ebfe9
Step 12/12 : CMD ["ts-node", "./src/server.ts"]
 ---> Using cache
 ---> 00a32820e6e2
Successfully built 00a32820e6e2
Successfully tagged backend-marketplace_backend:latest
backend-marketplace_database_1 is up-to-date
Starting backend-marketplace_backend_1 ...
Starting backend-marketplace_backend_1 ... error

ERROR: for backend-marketplace_backend_1  Cannot start service backend: failed to create shim task:
OCI runtime create failed: runc create failed: unable to start container process: error during container init:
error mounting "/var/lib/docker/volumes/3ceff6572cda1981f7d29faf09f888cb9a8c0c5ac41b10bb323eb5d14e7e1d35/_data"
to rootfs at "/app/node_modules": mkdir /var/lib/docker/overlay2/c0a5b761bb9a94bb9a4dd3c21a862968dbbabe87698c0f744569ea56e323ea0e/merged/app/node_modules:
read-only file system: unknown

ERROR: for backend  Cannot start service backend: failed to create shim task:
OCI runtime create failed: runc create failed: unable to start container process: error during container init:
error mounting "/var/lib/docker/volumes/3ceff6572cda1981f7d29faf09f888cb9a8c0c5ac41b10bb323eb5d14e7e1d35/_data" to rootfs at
"/app/node_modules": mkdir /var/lib/docker/overlay2/c0a5b761bb9a94bb9a4dd3c21a862968dbbabe87698c0f744569ea56e323ea0e/merged/app/node_modules:
read-only file system: unknown
ERROR: Encountered errors while bringing up the project.

I see docker-compose.yml and docker-compose.dev.yml mentioned so here they are:

docker-compse.yml:

version: "3"
services:
  backend:
    build: .
    ports:
      - "8000:8000"
    env_file:
      - ./.env

and docker-compose.dev.yml:

version: "3"
services:
  backend:
    build:
      context: .
      args:
        NODE_ENV: development
    volumes:
      - ./:/app:ro
      - /app/node_modules
    links:
      - database
    env_file:
      - ./.env
    command: npm run dev
  database:
    image: "postgres:latest"
    volumes:
      - pgdata:/var/lib/postgresql/data
    expose:
      - "5432"
    ports:
      - "5432:5432"
    env_file:
      - ./.env.database
  pgadmin:
    image: dpage/pgadmin4:latest
    ports:
      - 5454:5454/tcp
    environment:
      - PGADMIN_DEFAULT_EMAIL=<redacted>
      - PGADMIN_DEFAULT_PASSWORD=<redacted>
      - PGADMIN_LISTEN_PORT=5454
    depends_on:
      - database
volumes:
  pgdata:

I would love to say "I found a few threads and tried what they recommend", but to be honest I don't really understand them when I read them yet. The following threads might be related but they read like Latin to me.

"Error response from daemon: failed to create shim: OCI runtime create failed" error on Windows machine

Cannot start service api: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "python manage.py runserver

Cannot start service app: OCI runtime create failed: container_linux.go:349

Like, my guess from reading the error message is that there's some sort of write permission I need to turn on, because the error message ends in "read-only file system: unknown". Sadly, that's all I can contribute.

Acropolis answered 21/6, 2022 at 4:22 Comment(0)
A
16

A coworker solved my issue.

FROM node:16-alpine
ENV NODE_ENV="development"
WORKDIR /app
COPY package.json .
COPY package-lock.json .
ARG NODE_ENV
RUN apk add g++ make py3-pip
RUN npm install
RUN chown -R node /app/node_modules
RUN npm install -g ts-node nodemon
COPY . ./
ENV PORT 8000
EXPOSE $PORT
CMD ["ts-node", "./src/server.ts"]

I added RUN chown -R node /app/node_modules and it worked. He said the issue was Linux specific.

Acropolis answered 24/6, 2022 at 1:48 Comment(3)
to which file did you add this line?Flue
It was one of the Dockerfiles. A backend one. Sorry, can't find the actual change now in the repo; its been a while since I worked on the project.Acropolis
not knowing the file name, makes this reply useless unfortunately.Strickman
H
18

In my case, Docker Compose had timed out, and had corrupted the containers. I just had to:

  1. increase the compose timeout (COMPOSE_HTTP_TIMEOUT=480)
  2. clean the containers (docker (image|container|network) prune
  3. run compose again
Hagar answered 2/12, 2022 at 23:32 Comment(2)
For me the problem was indeed solved by 'docker container prune'Assay
can you please elaborate on the exact commands to run?Mn
A
16

A coworker solved my issue.

FROM node:16-alpine
ENV NODE_ENV="development"
WORKDIR /app
COPY package.json .
COPY package-lock.json .
ARG NODE_ENV
RUN apk add g++ make py3-pip
RUN npm install
RUN chown -R node /app/node_modules
RUN npm install -g ts-node nodemon
COPY . ./
ENV PORT 8000
EXPOSE $PORT
CMD ["ts-node", "./src/server.ts"]

I added RUN chown -R node /app/node_modules and it worked. He said the issue was Linux specific.

Acropolis answered 24/6, 2022 at 1:48 Comment(3)
to which file did you add this line?Flue
It was one of the Dockerfiles. A backend one. Sorry, can't find the actual change now in the repo; its been a while since I worked on the project.Acropolis
not knowing the file name, makes this reply useless unfortunately.Strickman
G
13

Linux is just picky when it comes to executing files as an executable (redundant I know).

So you create a text file (or binary file) with commands, but you want to then run that file and have it perform some job within the container, yet you will need to let the environment know that it has permissions to do so.

chown or chmod would do the trick.

A chmod approach:

RUN chmod +x ./src/server.ts

The level of permissions (+x for all) gives the executable the rights to do so within the container.

Gluttony answered 11/10, 2022 at 21:16 Comment(1)
This solve the issue after RUN chmod +x install.sh on the Dockerfile solve the issueHinda
D
9

In my case, it was with Docker Compose and starting containers and I just recreated them.

docker-compose down
docker-compose up -d
Dumbfound answered 6/3, 2023 at 14:2 Comment(2)
did not solve for us 🤷. And the coworker was no help neitherBrauer
did you try also with the flags? --rmi -v ( docs.docker.com/engine/reference/commandline/compose_down )Dumbfound
T
6

I was having this issue creating a Dockerfile with an Alpine base image. In the image creation, it copies a script to the image, and this script is what should execute when running containers with the created image. Because the Alpine image uses BusyBox, and there is no shell in BusyBox, the solution was to have one of the two entry points:

ENTRYPOINT ["/bin/sh","/my-script.sh"]

ENTRYPOINT ["/bin/bash","/my-script.sh"]

Using CMD would also do the trick.

Tampon answered 16/5, 2023 at 8:33 Comment(0)
O
0

In my case, I forgot to add npm i -g nodemon as I was working with multiple services.

Optic answered 2/3, 2023 at 1:43 Comment(0)
E
0

This might come late and the issue had been solved already but I stumbled upon this issue and maybe someone encounters something similar.

The error message that brought me here was the following:

ERROR: for restdjangoserver_restweb_1  Cannot start service restweb: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "python": executable file not found in $PATH: unknown

ERROR: for restweb  Cannot start service restweb: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "python": executable file not found in $PATH: unknown
ERROR: Encountered errors while bringing up the project.

I am working however with Django and my docker-compose container for django contains the following line:

command: python manage.py runserver 0.0.0.0:8000

However, in my version python itself doesn't exist, so I had to replace it with:

command: python3 manage.py runserver 0.0.0.0:8000
Earthenware answered 8/9, 2023 at 12:12 Comment(0)
C
0

For me the problem was the amount of resources required by deployment.yml VS the amount that the kubernetes cluster node could offer. In other words, it was demanding an amount of resources greater than what could be provided by the cluster hardware. By decreasing the amount of resources demanded by the application's deployment.yml the pod was able to scale 1/1 again, as usual.

(before solution) Example of the part of deployment.yml WITH problem:

resources:
  limits:
    cpu: "1024Mi"
    memory: "2024Mi"
  requests:
    cpu: "600m"
    memory: "1024Mi"

(after solution) Example of the deployment.yml part WITHOUT a problem:

resources:
  limits:
    cpu: "600m"
    memory: "1024Mi"
  requests:
    cpu: "100m"
    memory: "500Mi"

(note the reduction in demand for computing resources)

Carline answered 15/7 at 19:14 Comment(0)
S
-1

Another way is to remove containers created, and the dangling (related) images and volumes. This way it'll be a cleaner start.

  • remove containers created:
docker compose down
  • remove images one by one:
sudo docker rmi -f <image_id>
  • Note if you don't want to keep other images related to other deleted containers, run: sudo docker image prune -a
  • remove dangling volumes:
sudo docker volume prune

!!! Also, if you want to do in one step, docker provides the following command:

sudo docker system prune

For more info, please read: https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes

Severable answered 14/7, 2023 at 8:10 Comment(2)
I think your response is negative because you didn't provide the commands or the example but this was something commented on another response hereBallonet
Thanks @TheoOliveira. I'll update this sooner.Severable

© 2022 - 2024 — McMap. All rights reserved.