# How to install Docker Compose on Ubuntu

Docker Compose is particularly well-suited for **development and test environments** but also for smaller production deployments. We explain how you can easily orchestrate Docker applications on Ubuntu with Compose.

## What are the requirements for Docker Compose on Ubuntu?

Before you can [use Docker Compose](https://www.ionos.com/digitalguide/server/configuration/docker-compose-tutorial/), you must ensure that your system meets the following prerequisites:

- **Docker Engine**: Compose is an extension to the Docker Engine that you need to install.
- **Operating system**: Ubuntu, sudo user with root privileges.

Tip To use an operating system other than Linux, see our guide on how to install [Docker Compose on Windows](https://www.ionos.com/digitalguide/server/configuration/install-docker-compose-on-windows/) and [Docker Compose on macOS](https://www.ionos.com/digitalguide/server/configuration/docker-compose-on-mac/).

## Step-by-step guide to installing Docker Compose on Ubuntu

To use Docker Compose on Ubuntu, you must first install **Docker Engine** and verify that it’s running properly. Once [Docker](https://www.ionos.com/digitalguide/server/know-how/what-is-docker/) is running, download Compose and create the YAML file to configure your applications.

### Step 1: Download and install Docker Compose

Download the latest version of Docker Compose from the official **GitHub repository** by entering the following command in a terminal:

```shell
$ curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
```

Now, you can give Docker Compose **execute** rights:

```shell
$ sudo chmod +x /usr/local/bin/docker-compose
```

Use the `--version` option to check if Compose was successfully installed.

```shell
$ docker-compose --version
```

You’ll get the following output:

[![Image: Docker Compose Version](https://www.ionos.com/digitalguide/fileadmin/_processed_/b/1/csm_docker-compose-version-ubuntu_428c28abad.webp "Docker Compose Version")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-compose-version-ubuntu.png) If you see the version number, Docker Compose has been successfully installed. If installation fails, check the path.

You can also create a **symbolic link** to the */usr/bin* path:

```shell
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
```

### Step 2: Configure the docker-compose.yml file

To demonstrate the design of a **Docker Compose YAML file**, we use the Nginx image from the official Docker Hub for the container environment.

First, create a new folder in your home directory:

```shell
$ mkdir ~/compose-test
```

Swap to the directory and create a new folder for the root directory of your **Nginx environment**.

```shell
$ cd ~/compose-test
$ mkdir app
```

You can use any text editor like **nano** to create *index.html*.

```shell
$ nano app/index.html
```

Here’s the HTML code for a sample page:

```html
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Docker Compose Test</title>
</head>
<body>
    <h1>This is a Docker Compose Test Page for an Nginx container.</h1>
<div class="hash d-none" hidden>hash_1ef51b68b9d51d9f7172e07bd7e316db8738b0fe</div><script data-shy-copy-guard>(function(){var C=[0x00AD,0x200B,0x200C,0x200D,0x2060,0xFEFF];var s=function(t){for(var i=0;i<C.length;i++){t=t.split(String.fromCharCode(C[i])).join("");}return t;};document.addEventListener("copy",function(e){var sel=document.getSelection();if(!sel||sel.isCollapsed||!e.clipboardData){return;}e.clipboardData.setData("text/plain",s(sel.toString()));try{var d=document.createElement("div");d.appendChild(sel.getRangeAt(0).cloneContents());e.clipboardData.setData("text/html",s(d.innerHTML));}catch(x){}e.preventDefault();});})();</script></body>
</html>
```

Save and close the HTML file and create *docker-compose.yml*.

```shell
$ nano docker-compose.yml
```

The contents are divided into the version number of the configuration and the services block.

```YAML
version: '3.9'
services:
    web:
        image: nginx:alpine
        ports:
            - "8000:80"
        volumes:
- ./app:/usr/share/nginx/html
```

Within the services block, there is a single service named “web.” It is associated with the specified Nginx image and port redirection. In our configuration, any requests made to port 8000 on the host machine are redirected to the web container on port 80, where Nginx is running. Furthermore, we use a **shared volume between the host and container**. This makes the local “app” folder accessible to the Nginx application

### Step 3: Execute Docker Compose

With the following command we create a **web container** and run the container environment in the background:

```shell
$ docker-compose up -d
```

If the image specified in the YAML file is not present on the local system, it will be downloaded automatically.

To test whether the Nginx environment is running, enter the `ps` command.

```shell
$ docker-compose ps
```

The sample page you created earlier is now accessible on *localhost:8000* when you run the demo on your machine. If you’re using a remote server, simply specify the IP address of your server instead of “localhost”.

[![Image: Docker Compose sample page](https://www.ionos.com/digitalguide/fileadmin/_processed_/b/8/csm_docker-compose-test-page-ubuntu_f263b18904.webp "Docker Compose sample page")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-compose-test-page-ubuntu.png) Sample page for an Nginx container You can stop the container application using `stop`.

```shell
$ docker-compose stop
```

Tip Not sure how to get started with container tools? Check out our [Docker tutorial](https://www.ionos.com/digitalguide/server/configuration/docker-tutorial-installation-and-first-steps/) and our overview of [Docker Commands](https://www.ionos.com/digitalguide/server/know-how/docker-commands/). Or find out more about [Docker orchestration with Swarm and Compose](https://www.ionos.com/digitalguide/server/know-how/docker-orchestration-with-swarm-and-compose/).


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/docker-compose-on-ubuntu/](https://www.ionos.com/digitalguide/server/configuration/docker-compose-on-ubuntu/) for AI/LLM consumption.