Django shell mode in docker Django shell mode in docker python python

Django shell mode in docker


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


  1. Run docker exec -it --user desired_user your_container bash
    Running this command has similar effect then runing 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.
  2. Inside your container just run python manage.py shell


You can use docker exec in the container to run commands like below.

docker exec -it container_id python manage.py shell