Try Docker for yourself by checking out this repository!
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
hogwarts
spells
.gitignore
Dockerfile
LICENSE
README.md
docker-compose.yml
manage.py
requirements.txt

README.md

docker-hogwarts

Try Docker for yourself by checking out this repository!

What to do:

  1. Download Docker
  2. Download Docker Compose (If not on a Mac)
  3. Fork this repo into your own GitHub space
  4. Clone this repo onto your own machine

Run the project (Lumos)

docker-compose up 

Notice how two services are created: db_1 and web_1. See that migrations run and the server starts.

Create a superuser

In a new tab, run:

docker-compose run web --rm ./manage.py createsuperuser

Create sample data

Log into the admin at http://localhost:8000/admin/ and add some content.

Visit http://localhost:8000/spells/ to see a list of your data, and http://localhost:8000/spells/{pk}/ to see a detail view of your data.

More ideas

Migrations

Add new features to the Spell model, or add a new model or app.

Run

docker-compose run --rm web ./manage.py makemigrations 

And then run

docker-compose run --rm web ./manage.py migrate 

Django Shell (Apparate)

Hop into the shell with

docker-compose run --rm web ./manage.py shell 

And experiment with poking around by importing a model and running queries on it.

Add a new requirement

Update your requirements file with something like requests or another library you love. Stop Docker, then restart with:

docker-compose up --build 

See your images (Imago Revelio)

docker images 

See your running containers (Continens Revelio)

docker container ls 

or

docker ps 

Add a volume for your data

It's helpful in development (and pretty necessary in production) to have your data persist across containers and across coding sessions. Read more about volumes in the docs.

To add a data volume to your project, make these changes to docker-compose.yml:

services:
  db:
    ...
    volumes:
      - postgres_data:/var/lib/postgresql/data/

  web:
    ...

volumes:
  postgres_data:

First add a volume element under your db service and name it postgres_data. Include the path to where your data will be stored in your container.

Then, add another element at the same level as services called volumes, and refer to your postgres_data volumes.

Now you won't need to recreate your superuser and test data every time you shut down your containers.

Stop for the day (Nox)

docker-compose down 

Enrichment exercises

  1. Build your image from scratch and give it a name
  2. "Exec" into the Docker container with docker exec --it
  3. Stop and restart just the web container
  4. Add a new service to docker-compose.yml; maybe Redis?
  5. Add tests and run them using docker-compose run commands

Resources

This repo uses the Git Commit Message StyleGuide.