[Answered ]-Why is my docker image not running when using docker run (image), but i can run containers generated by docker-compose up?

1👍

The Compose command: overrides the Dockerfile CMD. docker run doesn’t look at the docker-compose.yml file at all, and docker run with no particular command runs the image’s CMD. You haven’t declared anything for that, which is why the container exits immediately.

Leave the entrypoint script unchanged (or even delete it entirely, since it doesn’t really do anything). Add a CMD line to the Dockerfile

CMD python manage.py migrate && python manage.py runserver 0.0.0.0:8000

Now plain docker run as you’ve shown it will attempt to start the Django server. For the Celery container, you can still pass a command override

docker run -d --net ... your-image \
  celery -A testapp worker -l INFO -c 4

If you do deploy to Kubernetes, and you keep the entrypoint script, then you need to use args: in your pod spec to provide the alternate command, not command:.

0👍

I think that is because the commands to run the django server are in the docker-compose.yml.

You should move these commands inside the entrypoint.

set -o errexit
set -o pipefail
set -o nounset

python manage.py migrate && python manage.py runserver 0.0.0.0:8000
exec "$@"

Pay attention that this command python manage.py runserver 0.0.0.0:8000 will start the application with a development server that cannot be used for production purposes.

You should look for gunicorn or similar.

Leave a comment