Django
using pip
settings.py
file to refer the database details from environment variables.
todo/models.py
file with below content,Task
model using
Django REST Framework.
Copy paste the below contents to your respective files,
http://localhost:8000/api/v1/tasks/
to see the list of tasks served from our Django app.
Voila! You have successfully created and run Django Python server with REST CRUD endpoints for Task model. 🎉
.dockerignore
file and add that contents that should not be copied over
to the docker file system.
.dockerignore
file and adding folders like node_modules
is must, since dependencies will be installed
while building the image based on the platform preferences used. Copying those from file system will overwrite the
installed dependencies and might fail during deploymententrypoint.sh
script to run DB migrations each
time the docker image is run.
source code
and dependencies to be present while running the application. You can opt for multi stage build,
if you have any build tool.
django-todo
image for platform linux/amd64
.
If you are locally testing your application, you can skip the platform
key to build the images
localhost:54321
.
docker-compose.yml
file with below
content,
http://localhost:8000/api/v1/tasks/
to list the tasks.
Hurray 🎉. Now we have created and Dockerized a Python Django app.