Conteúdo do Curso
Docker for Python Developers
Docker for Python Developers
Docker 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.
-
services
: This key defines the services (containers) we want to run using Docker Compose. -
web-app
: This is the service name we gave to the web application container. You can use any name you deem fit. -
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. -
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. -
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. -
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 address0.0.0.0
and port8000
.
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
.
Obrigado pelo seu feedback!