Cybersecurity Updates & Tools

Install Docker Compose on Ubuntu 18.04: Setup and Usage Guide

Docker Compose is a tool that lets you define and run multi-container Docker applications using a single YAML configuration file. Instead of managing containers one at a time with separate docker commands, you describe your entire application stack — services, networks, volumes, and environment variables, in one file and bring everything up with one command.

You can commit this file to version control and share it with your team. Anyone with Docker and Compose installed can spin up the exact same environment instantly. Compose is most commonly used for local development, automated testing pipelines, and single-host deployments.

Prerequisites: You need sudo access and Docker already installed on your Ubuntu machine.

Install Docker Compose on Ubuntu

The Docker Compose package in Ubuntu’s default repositories may not always be the latest version. Install directly from Docker’s GitHub releases instead.

Download the latest stable release — check the Compose releases page to confirm the current version before running this command:

bashsudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Make the binary executable:

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

Verify the installation:

bashdocker-compose --version

Define a Multi-Container App with Docker Compose

This example sets up a two-container WordPress application — a MySQL database and a WordPress web server — using a single Compose file.

Create a project directory and navigate into it:

bashmkdir my_appcd my_app

Create a docker-compose.yml file with the following content:

yamlversion: '3.3'services:  db:    image: mysql:5.7    restart: always    volumes:      - db_data:/var/lib/mysql    environment:      MYSQL_ROOT_PASSWORD: password      MYSQL_DATABASE: wordpress  wordpress:    image: wordpress    restart: always    volumes:      - ./wp_data:/var/www/html    ports:      - "8080:80"    environment:      WORDPRESS_DB_HOST: db:3306      WORDPRESS_DB_NAME: wordpress      WORDPRESS_DB_USER: root      WORDPRESS_DB_PASSWORD: password    depends_on:       - dbvolumes:    db_data:    wp_data:

Here is what this configuration defines:

  • db service – runs the mysql:5.7 image, creates a named volume db_data to persist the database across restarts, and sets the required MySQL environment variables
  • wordpress service – runs the WordPress image, maps port 8080 on the host to port 80 inside the container, and uses depends_on to ensure the database starts before WordPress
  • volumes block – declares the named volumes db_data and wp_data so data is not lost when containers restart

Start and Manage Your Compose Services

Start the application:

bashdocker-compose up

To run Compose in the background without blocking your terminal, use detached mode:

bashdocker-compose up -d

Once running, open http://localhost:8080 in a browser to see the WordPress installation screen. This confirms both containers are up and communicating correctly. Check the status of your services with:

bashdocker-compose ps

To stop services without removing the containers:

bashdocker-compose stop

To stop and remove the containers entirely:

bashdocker-compose down

To also delete the named data volumes — this permanently removes your database and stored files:

bashdocker-compose down --volumes

Uninstall Docker Compose

To remove Compose from your system, delete the binary:

bashsudo rm /usr/local/bin/docker-compose

Docker Compose is now installed on your Ubuntu 18.04 machine. With a single YAML file, you can define, start, and manage complex multi-container applications that would otherwise require many individual Docker commands. Leave a comment below if you run into any issues during setup.