How to fix “docker-compose: command not found”

Docker is a great way to manage different application processes in various environments using containers. While containers are similar to virtual machines in certain ways, they are more lightweight and resource-friendly.

Docker Compose is a tool allows you to run complex applications which involves multiple containers working together, all based on a set of rules defined in a YAML file.

In this article, we’ll cover the various possible causes of the "docker-compose: command not found" error message. Then we’ll share solutions for each common situation, to help you get your Docker-based containers up and running.

Why does “docker-compose: command not found” occur?

"docker-compose: command not found" simply indicates that the system cannot find docker-compose executable in its default location, usually /usr/bin or /usr/local/bin. This is similar to most of the other "command not found" errors, including “pip: command not found”conda: command not found or “apt-get command not found”.

There are several common things can lead to this error message:

  • Docker Compose v1 is not currently installed
  • docker-compose path is not included in PATH environment variable

docker-compose vs docker compose

While docker-compose is a part of Docker Engine itself, it hasn’t even been considered to be included in Docker up until recently. You need to install it separately after installing the engine. According to the documentation, there are two distinct Docker Compose version : v1 and v2.

In Docker Compose v1, docker-compose is the command in charge of managing almost everything.

Starting with Docker Compose v2, Docker has migrated towards using the compose CLI plugin command and away from the original docker-compose.

Generally speaking, any commands written for Docker Compose v1 can be converted to v2 by dropping the hyphen from docker-compose calls to become docker compose. For full compatibility details, consult the official Docker documentation on command compatibility between the new compose and the old docker-compose.

Fix : Reinstalling Docker Compose from source

Docker Compose is packaged into a single executable binary. You can install the latest version of Docker Compose by downloading it directly from Docker Github repository. The latest version of Docker Compose is listed on its release page.

  • First you need to download docker-compose binary and put it into /usr/local/bin/ by running the following command. Remember to replace the 1.24.0 version number to a suitable value according to Docker Compose release page. This command needs to be ran with root privileges to be able to write into /usr directory.
sudo curl -L "<a href="https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname">https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname</a> -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Code language: HTML, XML (xml)
  • After that, you have to give the docker-compose binary executable permssion
sudo chmod +x /usr/local/bin/docker-compose
  • Finally, confirm the installation and verify the Docker Compose version number by running the following command:
docker-compose --version

docker-compose directory not in PATH

Environment variables hold values related to the current environment, like the Operating System or user sessions. One of the most well-known is called PATH. It exists on most major OS, including Windows, Linux and Mac OS X. It specifies the directories in which executable programs are located on the machine that can be started without knowing and typing the whole path to the file on the command line.

If the parent directory of docker-compose isn’t present in PATH, the OS cannot intepret the command and make appropriate binary calls.

Suppose we’re having docker-compose inside /usr/local/bin and it’s not in PATH, we can run the following command to fix that. Remember to restart the machine so that changes can take effect.

echo 'export PATH="$PATH:/usr/local/bin"' >> ~/.bashrc
Code language: PHP (php)

The command above adds export PATH="$PATH:/usr/local/bin" into the bottom of ~/.bashrc, which appends /usr/local/bin to PATH every time you start a shell session.

Alternatively, you can create a symbolic link in /usr/bin, which was included in PATH by default, to achieve the same result.

<code>sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose</code>
Code language: HTML, XML (xml)

Now you can confirm docker-compose works fine by running docker-compose --version, you should see a version number in the terminal.

We hope that the information above helped you learn a bit more about docker-compose: command not found error. You may want to check out our tutorials for Docker such as How to fix Docker: “build” requires 1 argument"LookupError: unknown encoding: cp65001" error in Docker and locale.Error: unsupported locale setting in Docker.

If you spot an error in the article, please kindly correct us using the comment section below.

Click to rate this post!
[Total: 1 Average: 4]

Leave a Comment