Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Compose cannot start the service: exec "python manage.py runserver" failed

ErrorCannot start service api: OCI runtime create failed

Short answer

The container runtime was asked to run a program literally named 'python manage.py runserver', including the spaces. That happens when a whole command is placed in one list item, or in a Dockerfile exec form. Give each word as its own item, or write the command as a plain string in Compose.

  • Applies to Docker Engine 27, Docker Compose v2, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print how Compose resolved the command and entrypoint of the failing service.

    docker compose config | grep -nE 'command|entrypoint'
  2. 2Match what you see, then jump to its fix

    1. 1The text after exec: in the error is the full command with spacesThe whole command sits in one item of a list or JSON arrayFix
    2. 2The command contains &&, a pipe, or an environment variable such as $PORTThe command needs a shell, but none is usedFix

What does the error look like?

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

Cause 1 of 2

The whole command sits in one item of a list or JSON array

1Check

The exec form is parsed as a JSON array and starts the first item as the executable. If the array has one item with spaces in it, the runtime looks for a program with that exact name.

grep -nE 'CMD|ENTRYPOINT|command' Dockerfile docker-compose.yml

2Fix

Split the command so each word is a separate quoted item, using double quotes in a Dockerfile, or write it as a string in Compose.

# Dockerfile
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

# docker-compose.yml
command: python manage.py runserver 0.0.0.0:8000

3Verify

The service starts and stays up.

docker compose up -d --build api
docker compose ps api

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 2

The command needs a shell, but none is used

1Check

The Compose docs say the command field is not run inside the image's shell automatically, so shell features need an explicit shell call.

docker compose config | grep -n command

2Fix

Call the shell yourself, so that it handles the operators and variables.

command: ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]

3Verify

Both steps run, in order, in the logs.

docker compose logs api --tail 30

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Use double quotes in Dockerfile JSON arrays, one word per item.
  • Read the resolved config with docker compose config before running a changed file.
  • Move multi-step start commands into a small entrypoint script.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.