How to fix the “command not found: docker compose” error

There exist some causes that will invoke the problem of “command not found: docker compose”. As it is stated in the error statement, it usually occurs when the system does not have Docker compose installed.

Docker compose is a commonly used tool that allows us to exchange or define multi-container applications. Those multi-container applications can be run as a single service; thanks to docker-compose. This helps the applications avoid any delay in multiple environments.

In this guide, we have provided the causes of the error “command not found: docker compose” and listed the solutions.

Resolve “command not found: docker compose” Problem

There exist many different methods using which we can resolve the “command not found: docker compose” error. Some of the solutions are as follows.

Reason 1: Docker Compose is not installed

There exist some very common causes behind this “command not found” problem, one of which is that the docker-compose tool is not installed on the system. In this case, when attempting to run the docker-compose command, this error will be prompted on your screen.

Solution: Install Docker Compose

If you check the Docker compose version and it gives the error “Command ‘docker’ not found” this means that docker-compose is not installed on your system.

2 different versions exist that you can choose between to install. Version 2 we have already shown you how to update.

For version 1 run the following command to install:

$ sudo apt install docker-compose

Reason 2: Incorrect version of docker compose

One of the more commonly made mistakes can be in the syntax when trying to use the Docker Compose commands on ubuntu. Docker-Compose offers two versions, i.e., v1.x and v2.x.

Solution 1: Check the version and use the correct syntax 

To avoid this, we need to check the current version of Docker compose. We have provided the commands to check versions of the installed Docker-Compose and then choose the appropriate syntax to use the Docker-Compose.

Run this command to check for docker-1:

$ docker-compose version

If the command above gives the error “docker: ‘compose’ is not a docker command” then use the following command to check for version 2:

$ docker compose version

Once we know the Docker compose version, we can fix the error “command not found: docker compose” by using the correct corresponding syntax.

If the system has version 1 installed, we use this syntax:

$ docker-compose

If the system has version 2 installed, we use this syntax:

$ docker compose

Solution 2: Install Docker Compose 2

The following commands will download and install version 2 of Docker compose inside the directory “$HOME”. The first step is to update and upgrade your Ubuntu system using the commands shown below:

$ sudo apt update
$ sudo apt upgrade

The following commands will make create the directory and set its path:

$ DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
$ mkdir -p $DOCKER_CONFIG/cli-plugins

The next step is to download version 2 of docker-compose. This can be achieved using the curl command followed by the GitHub link for this tool as demonstrated below:

$ curl -SL https://github.com/docker/compose/releases/download/v2.6.1/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

Run this command to make it executable:

$ chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose

Once completed, run the command that was mentioned above to check the version again and it should show you version 2 of Docker compose.

Conclusion

The “command not found: docker compose” issue occurs when docker-compose is not installed onto the system or there is a conflict between the current version of docker-compose with the syntax that is being utilized. This error can be resolved by installing the correct version of docker-compose and using the corresponding syntax alongside that docker-compose.