what is it?
- a tool used for defining and running multi-container docker applications
- uses yaml files to configure the application’s services
- performs the creation and start-up processes for all of the containers with a single command
- another big benefit of using docker compose over spinning up containers with docker run, is that compose automatically links the different containers in a pseudo network
configuration
commands
-
build image (in same directory as docker-compose.yml):
docker compose build -
take down containers. the
remove-orphansflag ensures that all containers on the network are taken down, even if they not described in the docker-compose.yml anymoredocker compose down -v --remove-orphans -
spin up container (after building image) in detached mode:
docker compose up -d -
do above two in single step:
docker compose up -d --build -
view and follow logs:
docker compose logs -f -
enter shell of running container:
docker compose exec <service-name> bash -
(django) run migrations in container named web:
docker compose exec web python manage.py migrate