Skip to main content
Docker Compose runs several containers from one file. Describe your services, ports and volumes in compose.yaml, then run docker compose up -d in that folder to start everything in the background. Use docker compose ps to check it, docker compose pull && docker compose up -d to update, and docker compose down to stop and remove the containers.

Before you start

  • Install Docker and the docker-compose-plugin package. Check with docker compose version.
  • Run the commands as a user in the docker group, or add sudo in front of each one.
  • Use docker compose (with a space). The old docker-compose (with a hyphen) is Compose v1 and is no longer updated.

What is a compose.yaml file?

compose.yaml is a YAML file that lists your services (containers), the image each one runs, and its ports, environment variables and volumes (storage that survives when the container is replaced). Compose looks for compose.yaml (preferred) or compose.yml in the current folder. It still reads the older docker-compose.yml name. You don’t need a version: line. Compose ignores it and prints the attribute 'version' is obsolete.

How to create your first Compose app

This example runs WordPress with a MariaDB database.
1

Make a project folder

The folder name becomes the project name, so containers are called wordpress-wordpress-1 and wordpress-db-1.
2

Put secrets in a .env file

Create .env next to compose.yaml:
Compose reads .env from the project folder and fills in ${DB_PASSWORD}. Run chmod 600 .env so other users can’t read it.
3

Write compose.yaml

Services reach each other by service name, so WordPress connects to the database at db. The database has no ports: entry, so it is not reachable from the internet.
4

Check the file

This prints the final configuration with variables filled in, or an error with the line number.
5

Start the app

-d (detached) runs the containers in the background. Open http://203.0.113.10:8080 with your server’s IP.

How to check it worked

Docker Compose commands you will use

Run these inside the project folder.
docker compose down -v deletes the named volumes, which means your database and uploaded files. Plain docker compose down keeps them. Take a backup before using -v.

How to update containers with Docker Compose

pull downloads newer images. up -d recreates only the containers whose image or settings changed. Your volumes stay. Run docker image prune afterwards to remove the old images; see clean up Docker disk space.

How to keep a service private

Ports published with "8080:80" bypass ufw and firewalld. To reach a service only through a reverse proxy on the same server, bind it to localhost:

Frequently asked questions

Do containers start again after a reboot?

Yes, if the service has restart: unless-stopped or restart: always and the Docker service is enabled at boot. You don’t need a cron job or systemd unit.

Where are my volumes stored?

Named volumes live under /var/lib/docker/volumes/. List them with docker volume ls. To use a folder you choose, write a bind mount such as ./data:/var/lib/mysql instead.

Does depends_on wait until the database is ready?

No. Plain depends_on only sets the start order. WordPress connects on each page request, so it works as soon as the database has finished starting. For apps that need the database ready at start-up, add a healthcheck to the database and use the long depends_on form with condition: service_healthy.

Can I use the same compose.yaml on another server?

Yes. Copy the project folder, including .env, and run docker compose up -d. Copy volume data separately.

VPS and dedicated server guides

Every guide in this section.

Install Docker

Docker Engine and the Compose plugin.

Docker commands cheat sheet

Containers, images, volumes and logs.

Install Portainer

Deploy Compose stacks in a web UI.

Nginx reverse proxy

Put a domain and HTTPS in front of a container.

Checked against the official Docker Compose documentation on 4 November 2026; compose.yaml validated and Compose commands tested on Ubuntu 24.04 LTS with Docker Compose v5.6.1. Commands can differ on other releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026