Docker and Docker Compose Commands
In this lesson, we'll study a few Docker and Docker Compose commands.
Docker Compose is used for the coordination of multiple Docker containers. Microservices systems usually consist of many Docker containers. Therefore, it makes sense to start and stop the containers with Docker Compose.
Docker Compose #
Docker Compose uses the file docker-compose.yml
to store information
about the containers. The
Docker documentation
explains the structure of this file.
The Docker Compose lesson contains an example of a Docker Compose file.
Upon starting, docker-compose
outputs all possible commands. The
most important commands for Docker Compose are:
-
docker-compose build
generates the Docker images for the containers with the help of theDockerfiles
referenced indocker-compose.yml
. -
docker-compose pull
downloads the Docker images referenced indocker-compose.yml
from Docker hub. -
docker-compose up -d
starts the Docker containers in the background. Without-d
the containers will start in the foreground so that the output of all Docker containers happens on the console. It is not particularly clear which output originates from which Docker container. The option--scale
can start multiple instances of a service, e.g.docker-compose up -d --scale order=2
starts two instances of the order service. The default value is one instance. -
docker-compose down
stops and ...