Docker Compose with Django

Docker Compose with Django

December 25, 2021

We'll build a Django project from scratch and get it working locally first. Then we'll Dockerize and get it working with docker-compose.yml. Found this is more useful and the typical steps folks take to setting up Docker Compose.

Docker Compose Commands

docker-compose build
docker-compose up
docker-compose exec web

More:

docker-compose start
docker-compose stop

Docker Commands

docker build -t boltops/docker-compose-django .
docker run boltops/docker-compose-django
docker push boltops/docker-compose-django

Python Commands Summary

Build Project

django-admin startproject mysite
vim requirements.txt
pip install -r requirements.txt
vim mysite/settings.py # change db, dont forget import os
python manage.py runserver
mysql -uroot -e 'create database mysite_development'
python manage.py migrate

Add polls app

python manage.py startapp polls
vim polls/models.py
vim polls/urls.py
vim mysite/settings.py # install app
python manage.py makemigrations polls
python manage.py sqlmigrate polls 0001
python manage.py migrate
python manage.py shell

Shell Testing

from polls.models import Choice, Question
Question.objects.all()
Question.objects.all().count()

Create admin user

python manage.py createsuperuser

Links:

Kubernetes Deploy Tools
48m

Get full access to these great resources

All for less than the price of coffee a day

44 courses
286 lessons
46+ hours

Get started with BoltOps Learn now and get access to easy and powerful lessons

BoltOps Tools