10

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 https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose

And verified successful installation with:

$ docker compose version
Docker Compose version v2.2.3

However, 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.sock

How can I make Docker Compose recognize the correct docker.sock file?

3
  • Your question title doesn't match the description of your question. The error you are showing when using docker-compose is that the command is not found in your $PATH and not related to the docker.sock issue
    – Dan
    Mar 9, 2022 at 12:32
  • See my answer below - the syntax is wrong. It should be docker compose instead of docker-compose when using V2. Mar 9, 2022 at 12:33
  • 1
    @ArturMeinild you were right on the money... the software package that I installing includes the hyphen in the instructions... thanks for the pointer.
    – nightwatch
    Mar 9, 2022 at 12:36

1 Answer 1

17

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 -d

I 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.

If you want to retain compatibility with the old syntax, you could create an alias like this:

alias docker-compose='docker compose'

This should work for most cases.

See here for the reference to the new V2 syntax.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.