conference logo

Playlist "An Intro to Docker for Djangonauts"

An Intro to Docker for Djangonauts

Lacey Williams Henschel

If you've never used it before, Docker can be a little overwhelming. There is new vocabulary to learn, new commands to memorize, and new files to add to each project. Most resources fall into one of two camps: they teach you the bare bones of Docker but still leave you with too many questions to comfortably try it on your own, or they throw you into the deep end by assuming you're more familiar with Docker than you are.

In this talk, you will find that middle ground: a talk that doesn't assume you're familiar with Docker and so keeps everything simple, but leaves you with enough information that you can get started as soon as you leave the room. Together, we will step through the parts of a Dockerfile and learn what they do. Then, I'll introduce you to Docker Compose and explain why using it to run multiple containers is helpful. Finally, you will learn to run commands and execute scripts from the command line using Docker, how to enter a container and why you might need to, and what to do before you go home for the day.

This talk is for Djangonauts who are curious about Docker, need to learn to use it for work or personal projects, or who seek a better understanding of containers in general. Audience members might be beginners to Python/Django or not, but they are definitely beginners to containerizing all the things.

The audience should be familiar with basic Python concepts such as variables and running things from the command line. Some basic familiarity with Django would be helpful, as the sample project I will demo is a Django app, but beginner Djangonauts will be able to follow along.

1. Introduction - Who am I? (1 minute)
2. What is Docker? Why use it? (3 min)
- Eliminates "it works on my machine" problems
- Never install anything globally ever again
- Great for working with teams
3. Docker definitions (4 min)
- Image
- Container
- Dockerfile
- Where do virtual environments fit in?
4. Dockerfile (5 min)
- Go through parts: Python image, setting environment variables, dealing with requirements.txt, set working directory of /code/, expose port
5. Docker Compose
- What is Docker Compose? (3 min)
- Allows you to run more than one container in a Docker application
- Useful for running multiple services like your web server, database, Redis, etc. in separate containers as part of one Docker application
- docker-compose.yml (6 min)
- Version
- Define services (db and web for this presentation)
- Explain volumes
- Run commands from services, like runserver
- Define dependencies
6. Docker on the Command Line (8 min)
- docker-compose up
- manage.py commands (docker-compose run web ./manage.py [command])
- running tests (docker-compose run web py.test [or ./runtests.py])
- opening a shell (docker-compose run web bash)
- viewing containers (docker ps) and entering a container (see where the /code/ dir is that we created in the Dockerfile)
- docker-compose down
7. Q&A (any remaining time)