Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Docker Compose | Advanced Concepts
Docker for Python Developers
course content

Course Content

Docker for Python Developers

Docker for Python Developers

1. Key Docker Concepts
2. Quick Start
3. Docker for Flask
4. Advanced Concepts

bookDocker Compose

Docker Compose is a tool for orchestrating and managing multi-container applications in the Docker environment. It allows defining the entire structure of an application in a single file called docker-compose.yml, instead of running each container separately using Docker commands.

Dockerfile is used to build individual container images for each component of your application.

Docker Compose utilizes these images and describes how these containers should be launched and connected using configuration files.

Using Docker Compose alongside Dockerfile simplifies the deployment and management process of multi-container applications, making it more systematic and easier to understand.

  1. services: This key defines the services (containers) we want to run using Docker Compose.

  2. web-app: This is the service name we gave to the web application container. You can use any name you deem fit.

  3. build: This key instructs Docker Compose to build the container from Docker files located in the current directory ("."). Typically, you would specify the path to the Dockerfile, but in this case, it's used with the root directory.

  4. ports: This key tells Docker which ports of the container should be accessible on the host machine. In this case, the web application container maps port 8000 to port 8000 on the host machine as well.

  5. volumes: This key tells Docker to mount the local directory ./planner into the container at the path /planner. This can be useful, for example, for persisting data between container launches.

  6. command: This is the command that will be executed when the container starts. In this case, it executes three commands sequentially, separated by &&:

    • python manage.py makemigrations: This command generates Django migration files based on changes in the database models.
    • python manage.py migrate: This command applies the generated migrations to update the database.
    • python manage.py runserver 0.0.0.0:8000: This command starts the Django web server on all available interfaces at the address 0.0.0.0 and port 8000.

This Docker Compose file defines a web application service that will run in a Docker container, built based on the current directory, with Django database migrations applied, and the Django server started.

Task

  • Clone this repository to explore this project:
  • Run the commands below to build the container and start it:

In summary, docker-compose build is used to build Docker images, while docker-compose up is used to start containers based on those images defined in the docker-compose.yml file. These commands are essential for managing multi-container applications using Docker Compose.

  • Navigate in the browser to port 0.0.0.0:8000.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 2
We're sorry to hear that something went wrong. What happened?
some-alt