I am learning how to develop Django application in docker with this official tutorial: https://docs.docker.com/compose/django/
I have successfully run through the tutorial, and
docker-compose run web django-admin.py startproject composeexample .
creates the image
docker-compose up
runs the application
The question is:
I often use python manage.py shell
to run Django in shell mode, but I do not know how to achieve that with docker.
Docker is a containerization tool used for spinning up isolated, reproducible application environments. This piece details how to containerize a Django Project, Postgres, and Redis for local development along with delivering the stack to the cloud via Docker Compose and Docker Machine.
I use this command (when run with compose)
docker-compose run <service_name> python manage.py shell
where <service name>
is the name of the docker service(in docker-compose.yml).
So, In your case the command will be
docker-compose run web python manage.py shell
https://docs.docker.com/compose/reference/run/
When run with Dockerfile
docker exec -it <container_id> python manage.py shell
docker exec -it --user desired_user your_container bash
ssh
to remote server - after you run this command you will be inside container's bash terminal. You will be able to run all Django's manage.py commands.python manage.py shell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With