Docker Compose can't execute: "Command 'docker-compose' not found"
I have installed the latest Docker Compose as a non-sudo user on Ubuntu Server 20.04 along with docker-rootless daemon in the non-sudo user's directory, using the following:
mkdir -p ~/.docker/cli-plugins/
curl -SL -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-composeAnd verified successful installation with:
$ docker compose version
Docker Compose version v2.2.3However, whenever I try to execute docker-compose up -d for a .yml file that I have created, I get the following output:
$ docker-compose up -d
WARNING:root:could not open file '/etc/apt/sources.list.d/mongodb-org-5.0.list'
Command 'docker-compose' not found, but can be installed with:
snap install docker # version 20.10.11, or
apt install docker-compose # version 1.25.0-1
See 'snap info docker' for additional versions.Docker Compose is not finding the correct docker.sock file although my non-root user's ~/.bashrc file contains:
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1007/docker.sockHow can I make Docker Compose recognize the correct docker.sock file?
1 Answer
You're making a very basic mistake in your Docker Compose command.
Docker Compose V1 has the command syntax docker-compose (docker-compose is a separate command).
Docker Compose V2 has the command syntax docker compose (compose is a subcommand of the docker command).
Since you have installed Docker Compose V2 branch, you can't use docker-compose up -d, but should instead use the correct V2 syntax:
docker compose up -dI would assume that most installation instructions will still use the old syntax docker-compose for some time, until V2 has become more mainstream. In the meantime, remember to replace with the new syntax if you're running V2.
See here for the reference to the new V2 syntax.