Cloud Native 9 min read

Master Docker Compose: Install, Configure, and Deploy Multi-Container Apps

Learn how to install Docker Compose, configure its permissions, verify installation, and use it to define services, images, ports, volumes, and environment variables in a docker‑compose.yml file, then manage containers with common commands to deploy and run multi‑container applications efficiently.

macrozheng
macrozheng
macrozheng
Master Docker Compose: Install, Configure, and Deploy Multi-Container Apps

What is Docker Compose?

Docker Compose is a tool for defining and running multi‑container Docker applications. You configure services in a YAML file and deploy them with a single command.

Installation

Download Docker Compose

curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Make the file executable

chmod +x /usr/local/bin/docker-compose

Verify installation

docker-compose --version

Steps to Use Docker Compose

Define the application environment with a Dockerfile when you need to modify the base image.

Define services to be deployed in a docker‑compose.yml file for one‑click deployment.

Run docker-compose up to launch all services at once.

Common docker‑compose.yml Options

image

Specify the image name to run.

# Use MySQL 5.7 image
image: mysql:5.7

container_name

Set the container name.

container_name: mysql

ports

Map host and container ports (HOST:CONTAINER).

ports:
  - 3306:3306

volumes

Mount host files or directories into the container (HOST:CONTAINER).

volumes:
  - /mydata/mysql/log:/var/log/mysql
  - /mydata/mysql/data:/var/lib/mysql
  - /mydata/mysql/conf:/etc/mysql

environment

Configure environment variables.

environment:
  - MYSQL_ROOT_PASSWORD=root

links

Link services (SERVICE:ALIAS).

links:
  - db:database

Common Docker Compose Commands

Build, create, and start containers

# Run in detached mode
docker-compose up -d

Stop all containers

docker-compose stop

List container information

docker-compose ps

Deploy an Application with Docker Compose

Write docker‑compose.yml

Docker Compose groups containers into three layers: project, service, and container. Services are defined under the services key, and containers can reach each other by service name.
version: '3'
services:
  db:
    image: mysql:5.7
    container_name: mysql
    ports:
      - 3306:3306
    volumes:
      - /mydata/mysql/log:/var/log/mysql
      - /mydata/mysql/data:/var/lib/mysql
      - /mydata/mysql/conf:/etc/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
  mall-tiny-docker-compose:
    image: mall-tiny-docker-compose:0.0.1-SNAPSHOT
    container_name: mall-tiny-docker-compose
    ports:
      - 8080:8080
    volumes:
      - /etc/localtime:/etc/localtime
      - /mydata/app/mall-tiny-docker-compose/logs:/logs

Note: If the mall‑tiny‑docker‑compose service cannot connect to MySQL, create a mall database in MySQL and import the mall.sql script.

Build the image with Maven plugin

Note: For build issues, refer to “Using Maven Plugin to Build Docker Images”.

Run Docker Compose to start all services

Upload docker-compose.yml to the Linux server and run:

docker-compose up -d

Access the API documentation at http://192.168.3.101:8080/swagger-ui.html:

Project Source Code

https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-docker-compose

Recommended Reading

Using Maven Plugin to Build Docker Images

Essential Docker Commands for Developers

Essential Linux Commands for Developers

Deploying Mall on Linux with Docker

Deploying Mall on Windows

Building Basic Skeleton with SpringBoot+MyBatis

Integrating Swagger‑UI for Online API Docs

Integrating SpringSecurity and JWT (Part 1)

Integrating Elasticsearch for Product Search

Integrating MongoDB for Document Operations

Integrating RabbitMQ for Delayed Messages

Integrating OSS for File Upload

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpsYAMLContainersDocker Compose
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.