compose: `docker: 'compose' is not a docker command` when installing using convenience scripts

Description of the issue

I’m confused by the instructions for installing compose V2 on Linux and the convenience scripts don’t result in a working docker compose. This is kinda complicated just to get a working docker compose, would be nice if it all worked with convenience scripts. Really my goal is to add the alias docker-compose (from https://github.com/docker/compose-switch) but I think I need docker compose working first?

Context information (for bug reports)

  • [X ] Using Compose V2 docker compose ...
  • Using Compose V1 docker-compose ...

Output of docker(-)compose version

none yet trying to install

Output of docker version

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Client: Docker Engine - Community
 Cloud integration: 1.0.17
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:54:27 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Steps to reproduce the issue

I’m assuming I should be able to install the docker / docker compose command line client inside a Linux container (I do that with docker and V1 docker-compose). Of course I’m only trying to run the docker client, the docker server is not running in the container.

  1. Create a Linux container on which you want the docker cli with the V2 compose subcommand. Btw it seems important that these convenience scripts work on centos/compatible too.
% docker run -ti ubuntu:20.04 bash

root@d8f753341dec:/# apt-get update && apt-get install -y curl

root@d8f753341dec:/# docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:54:27 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

  1. Install the V2 docker compose cli:
root@d8f753341dec:/# curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh     
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
Running checks...  0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  5982  100  5982    0     0  31650      0 --:--:-- --:--:-- --:--:-- 31819
Checks passed!
Downloading CLI...
Downloaded CLI!
Installing CLI...
Done!
  1. I’d expect that to make docker compose work, but it does not.
root@d8f753341dec:/# docker compose version
docker: 'compose' is not a docker command.
See 'docker --help'

Observed result

docker: 'compose' is not a docker command.

Expected result

% docker compose version
Docker Compose version v2.0.0-rc.3

Additional information

Docker for Mac 4.0.2

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25

Most upvoted comments

Since this page is now ranking for docker: 'compose' is not a docker command on Google, here’s how you fix it on Ubuntu:

sudo apt-get install docker-compose-plugin

in case you installed docker and docker-compose v2 with homebrew on OSX and getting docker: 'compose' is not a docker command

then you need to run these commands:

$ mkdir -p ~/.docker/cli-plugins
$ ln -sfn /opt/homebrew/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose

@keunes

From the OP’s reaction it seems a solution is suggested above, but it’s too cryptic for me to understand 😃 It would be great to have some further instructions, if anything needs to be done differently than what is written in the docs, or if I need to do something extra after.

The instructions on the website assume installation on an x86_64 platform. Your Raspberry Pi will instead require an armhf / aarch64 binary. You’ll need to run these commands instead:

  1. DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
    mkdir -p $DOCKER_CONFIG/cli-plugins
    
  2. For Raspberry Pi 1, 2, or later versions running a 32-bit (armv7) operating system:

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

    For Raspberry Pi 3 or 4 running a 64-bit (aarch64) operating system:

    curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-aarch64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
    
  3. chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
    

in case you installed docker and docker-compose v2 with homebrew on OSX and getting docker: 'compose' is not a docker command

then you need to run these commands:

$ mkdir -p ~/.docker/cli-plugins
$ ln -sfn /opt/homebrew/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose

THANK YOU THANK YOU THANK YOU

Compose Switch is indeed a translator to offer a smooth transition for docker-compose commands to actually run Compose V2, so the later need to be installed first.

Linux installation is documented here: https://github.com/docker/compose/tree/v2#linux Basically, as a CLI plugin, you just need to download the Compose V2 binary and place it in the cli-plugins directory as docker-compose.

Try with (Ubuntu 20.04.6):

sudo apt-get update
sudo apt-get install docker-compose-v2

@ndeloof @jamshid Sorry to bug you - I am trying to install docker compose V2 on Raspberry Pi OS, and I am experiencing the same issue: I get docker: 'compose' is not a docker command. despite following the steps in the docs.

From the OP’s reaction it seems a solution is suggested above, but it’s too cryptic for me to understand 😃 It would be great to have some further instructions, if anything needs to be done differently than what is written in the docs, or if I need to do something extra after.

All the best

in case you installed docker and docker-compose v2 with homebrew on OSX and getting docker: 'compose' is not a docker command

then you need to run these commands:

$ mkdir -p ~/.docker/cli-plugins
$ ln -sfn /opt/homebrew/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose

Adding to @dmshvetsov answer, if you use Homebrew to install docker-compose you can use its CLI to define the docker-compose installation directory during the symlink creation. Also, it is necessary to create DOCKER_CONFIG environment variable as described on “Install The Plugin Manually” section on Docker Compose documentation

DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
ln -sfn $(brew --prefix docker-compose)/bin/docker-compose $DOCKER_CONFIG/cli-plugins/docker-compose

You can also add DOCKER_CONFIG on your shell rc file (like .zshrc or .bashrc) to prevent setting it every time you want to use Docker Compose.

echo -e "\nexport DOCKER_CONFIG=\${DOCKER_CONFIG:-\$HOME/.docker}" >> ~/.zshrc

Thanks @ndeloof ok I get it now. FYI this is what I’m using in my Dockerfile to get a working docker client and V2 docker compose with the alias docker-compose.

ENV DOCKER_VERSION 20.10.7
RUN curl -sSLf https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz | tar -xzvf - docker/docker && chmod +x docker/* && mv docker/* /bin

RUN test "$(uname -m)" = "aarch64" && TARGET_ARCH=arm64 || TARGET_ARCH=amd64 ; \
    mkdir -p ~/.docker/cli-plugins && \
    curl -fsSL "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSEV2_VERSION-v2.0.0-rc.3}/docker-compose-linux-${TARGET_ARCH}" -o ~/.docker/cli-plugins/docker-compose && \
    chmod +x ~/.docker/cli-plugins/docker-compose && \
    curl -fsSL -o /usr/local/bin/docker-compose https://github.com/docker/compose-switch/releases/download/v1.0.2/docker-compose-linux-${TARGET_ARCH} && \
    chmod +x /usr/local/bin/docker-compose && \
    docker --version && docker compose version && docker-compose version

Build outputs:

Docker version 20.10.7, build f0df350
Docker Compose version v2.0.0-rc.3
Docker Compose version v2.0.0-rc.3
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose

Install it using

sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

Test it

docker compose version

Source

Note to self and others: if when trying to run docker compose you get an error like below, then set your system to Manage Docker as a non-root user. After that I didn’t have the error any-more.

pi@raspberry:/nextcloud-docker $ docker compose up
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.project%3Dnextcloud-docker%22%3Atrue%7D%7D&limit=0": dial unix /var/run/docker.sock: connect: permission denied

Any help on mac, tried Installing both docker and docker-compose via homebrew, still no luck.

@gopalmani If you have installed docker-compose you can use that command instead of docker compose. Alternatively, you can remove both docker and docker-compose, then brew install docker --cask to install Docker Desktop, which also installs the CLI tools needed to run docker compose.

sudo apt-get install docker-compose-plugin Reading package lists… Done Building dependency tree… Done Reading state information… Done E: Unable to locate package docker-compose-plugin

arch: pacman -S docker-compose

Any help on mac, tried Installing both docker and docker-compose via homebrew, still no luck.

Since this page is now ranking for docker: 'compose' is not a docker command on Google, here’s how you fix it on Ubuntu:

sudo apt-get install docker-compose-plugin

Thanks, worked like a charm.

The instructions for V1 contain $(uname -m) in the download URL, which automatically injects the right architecture in the URL.

Keep in mind that for Ubuntu on a Raspberry Pi 2, at least, $(uname -m) will return armv7l instead of armv7. The binary will run on the platform, regardless.