How To

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.

Cyber Defence

Recent Posts

Install PHP on Ubuntu 26.04: Apache, Nginx, and Multiple Versions

PHP 8.5 is included in Ubuntu 26.04's default repositories and is the recommended version for…

13 hours ago

Upgrade to Ubuntu 26.04 from 25.10 and 24.04 LTS: Complete Guide

Ubuntu 26.04 LTS "Resolute Raccoon" arrived on April 23, 2026 with Linux kernel 7.0, GNOME 50,…

13 hours ago

Install Kubernetes on Ubuntu 26.04 with kubeadm and containerd

Kubernetes is the standard platform for running containerized workloads across multiple servers with self-healing, rolling…

13 hours ago

Install Ubuntu 26.04: Bootable USB, Partitioning, and First Steps

Ubuntu 26.04 LTS "Resolute Raccoon" was released on April 23, 2026 with Linux kernel 7.0, GNOME desktop, and standard security support until April 2031. A clean install gives you a known-good starting point on new hardware, when replacing another operating system, or when an upgrade path is not practical. This guide walks through how to install Ubuntu 26.04: downloading and verifying the ISO, writing a bootable USB drive, completing the installer, and doing the initial setup after the first boot. Before you start: You need a USB drive with at least 12 GB of free space. Back up any existing data on the target machine — the installer can erase the entire disk. Install Ubuntu 26.04: Download the ISO…

13 hours ago

Change Timezone on Ubuntu: timedatectl and Desktop GUI Guide

The correct timezone affects more than the clock on your screen. It drives cron job scheduling, systemd timer execution, log file timestamps, database record timing, and SSL certificate validity checks. A mismatched timezone can cause scheduled jobs to fire at the wrong hour and make log timestamps impossible to match with real-world events. This guide shows how to change timezone on Ubuntu using the timedatectl command (the recommended approach for servers and remote machines) and through the graphical Date & Time settings on desktop systems. The steps apply to all current Ubuntu releases including 24.04 and 26.04. <strong>Prerequisite:</strong>&nbsp;Only&nbsp;the&nbsp;root&nbsp;user&nbsp;or&nbsp;a&nbsp;user&nbsp;with&nbsp;sudo&nbsp;access&nbsp;can&nbsp;change&nbsp;the&nbsp;system&nbsp;timezone. Check the Current Timezone Before You Change It Run timedatectl with no arguments to see the active timezone and clock status: bashtimedatectl Sample output: Local…

13 hours ago

Install Atom on Ubuntu 18.04: GitHub’s Code Editor APT Setup

Atom is a free, open-source, cross-platform code editor developed by GitHub. Built on Electron, it uses…

1 day ago