Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django shell mode in docker

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.

like image 306
Justin Li Avatar asked Jun 11 '17 18:06

Justin Li


People also ask

What is the use of Docker in Django?

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.


2 Answers

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
like image 177
anmolakhilesh Avatar answered Sep 19 '22 14:09

anmolakhilesh


  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
like image 36
Jan Giacomelli Avatar answered Sep 16 '22 14:09

Jan Giacomelli