Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Docker Compose on Ubuntu

Install Docker, add the Compose plugin and run a first multi-container project.

What you need

  • Ubuntu 20.04, 22.04 or newer.
  • Root or sudo access.
  • An internet connection.
  • Docker (step 2 installs it).

Step 1: Update Ubuntu

sudo apt update && sudo apt upgrade -y

Step 2: Install Docker

sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
docker --version

(For the newest Docker version, use the official Docker repository instead of docker.io.)

Step 3: Install Docker Compose

Install the Compose plugin:

sudo apt install docker-compose-plugin

If the package is not found, add the official Docker repository first, or install docker-compose-v2:

sudo apt install docker-compose-v2

Check it:

docker compose version

Step 4: Create a Compose file

mkdir docker-project
cd docker-project
nano docker-compose.yml

Add:

services:
  web:
    image: nginx
    ports:
      - "8080:80"

(The line version: '3' is no longer needed in current Compose versions.)

Start it in the background:

docker compose up -d

Open http://your_server_ip:8080. You see the Nginx welcome page.

Step 5: Manage the containers

CommandWhat it does
docker compose up -dStarts the services in the background
docker compose downStops and removes the containers and the network
docker psLists the running containers
docker compose logsShows the logs
docker compose psShows the services of the project
docker compose restartRestarts the services
docker compose pullDownloads newer images

Why Compose is useful

  • One file for the whole app. Web server, database, cache and more.
  • Repeatable. The same setup works on every machine.
  • Easy to share. Put the file in Git.
  • Simple commands to start and stop everything.

Quick recap

  • Install Docker and the docker-compose-plugin.
  • Write docker-compose.yml.
  • Use docker compose up -d and docker compose down.