How to do it...

To get started, we need to create a docker-compose.yml file. This is in YAML format, which is a simple text-based language with a strong focus on readability. Here's what our docker-compose.yml file looks like:

version: '3' 
 
networks: 
  webnet: 
 
services: 
  redmine: 
    image: redmine 
    networks: 
      webnet: 
        aliases: 
          - demo-redmine 
 
  nginx-proxy: 
    build: ./ 
    ports: 
      - 443:443 
    networks: 
      - webnet 

This is located in the same directory as Dockerfile and the previous NGINX configuration files we used. The directory naming is also important, as Docker Compose will use it to prepend the names of the containers it creates. For this recipe, I have the files located in the composedemo directory.

With our Docker Compose configuration file, we can now build and create the containers:

docker-compose up  

This will firstly build our nginx-proxy image and then proceed to create all the containers. You should see an output like this as the containers start:

Creating network "composedemo_webnet" with the default driver
Creating composedemo_redmine_1
Creating composedemo_nginx-proxy_1
Attaching to composedemo_nginx-proxy_1, composedemo_redmine_1  

The naming is reflective of the configuration we used, where it prepends the directory name, adds the container name, and then appends a sequence number.

After the containers have been started, all the logs will output to the screen, and the containers will be running in the foreground. If you want to start it in the background, you can do this with the following:

docker-compose run -d  

This starts the containers in the background, much like our previous recipe. They can also be stopped with one command:

docker-compose stop  

With the ability to cleanly define the multicontainer deployments and then deploy with a single command, Docker Compose is an important part of the Docker ecosystem.