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


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/ # change db, dont forget import os
python runserver
mysql -uroot -e 'create database mysite_development'
python migrate

Add polls app

python startapp polls
vim polls/
vim polls/
vim mysite/ # install app
python makemigrations polls
python sqlmigrate polls 0001
python migrate
python shell

Shell Testing

from polls.models import Choice, Question

Create admin user

python createsuperuser


Get full access to these great resources

All for less than the price of coffee a day

27 courses
184 lessons
28+ hours

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

BoltOps Tools