1

This is my Dockerfile.template

...
CMD python3 manage.py makemigrations --noinput
CMD python3 manage.py migrate --noinput
CMD python3 manage.py runserver 0.0.0.0:8000
...

But for some reasons the application goes straight into serving

I'm running the docker container like so:

docker run -t --rm -p 8000:8000 {myimage}

I found this behavior to be strange so I decided to hop in

docker exec -it d2836730ae55 bash
python3 manage.py makemigrations --noinput
python3 manage.py migrate --noinput

And this runs fine, so it seems like docker run somehow is skipping the other commands. What am I doing wrong?

Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
  • A container only has one command, and every `CMD` except the last one is ignored. [How do you perform Django database migrations when using Docker-Compose?](https://stackoverflow.com/questions/33992867/how-do-you-perform-django-database-migrations-when-using-docker-compose) discusses two primary ways to run migrations (in a separate container, or making `CMD` be a shell script). – David Maze Oct 09 '20 at 11:36
  • Aaaah that makes sense. – Stupid.Fat.Cat Oct 09 '20 at 14:45

0 Answers0