ChatGPT解决这个技术问题 Extra ChatGPT

sudo: docker-compose: command not found

I am trying to run docker-compose using sudo.

I have both docker and docker-compose installed on Ubuntu 16.01.

Due to an error while trying to download compose using curl, I ended up installing it using pip.

Docker version 1.12.0, build 8eab29e docker-compose version 1.8.0, build 94f7016

Yet, when I try to run docker-compose with sudo I get the following (using sudo with docker is fine)

sudo: docker-compose: command not found

I suppose there are differing definitions of what 'installed' means. I have been using docker-compose on the same computer that claims it is not installed.

$ dpkg -s docker-compose
dpkg-query: package 'docker-compose' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.


$ whereis docker-compose
docker-compose: /home/user/.local/bin/docker-compose

$ pip show --files docker-compose
---
Metadata-Version: 2.0
Name: docker-compose
Version: 1.8.0
Summary: Multi-container orchestration for Docker
Home-page: https://www.docker.com/
Author: Docker, Inc.
Author-email: UNKNOWN
Installer: pip
License: Apache License 2.0
Location: /home/anton/.local/lib/python2.7/site-packages
Requires: six, jsonschema, enum34, cached-property, websocket-client, docker-py, requests, docopt, dockerpty, PyYAML, texttable
Classifiers:
  Development Status :: 5 - Production/Stable
  Environment :: Console
  Intended Audience :: Developers
  License :: OSI Approved :: Apache Software License
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.4
Files:
  ../../../bin/docker-compose
  compose/GITSHA
  compose/__init__.py
  compose/__init__.pyc
  compose/__main__.py
  compose/__main__.pyc
  compose/bundle.py
  compose/bundle.pyc
  compose/cli/__init__.py
  compose/cli/__init__.pyc
  compose/cli/colors.py
  compose/cli/colors.pyc
  compose/cli/command.py
  compose/cli/command.pyc
  compose/cli/docker_client.py
  compose/cli/docker_client.pyc
  compose/cli/docopt_command.py
  compose/cli/docopt_command.pyc
  compose/cli/errors.py
  compose/cli/errors.pyc
  compose/cli/formatter.py
  compose/cli/formatter.pyc
  compose/cli/log_printer.py
  compose/cli/log_printer.pyc
  compose/cli/main.py
  compose/cli/main.pyc
  compose/cli/signals.py
  compose/cli/signals.pyc
  compose/cli/utils.py
  compose/cli/utils.pyc
  compose/cli/verbose_proxy.py
  compose/cli/verbose_proxy.pyc
  compose/config/__init__.py
  compose/config/__init__.pyc
  compose/config/config.py
  compose/config/config.pyc
  compose/config/config_schema_v1.json
  compose/config/config_schema_v2.0.json
  compose/config/environment.py
  compose/config/environment.pyc
  compose/config/errors.py
  compose/config/errors.pyc
  compose/config/interpolation.py
  compose/config/interpolation.pyc
  compose/config/serialize.py
  compose/config/serialize.pyc
  compose/config/sort_services.py
  compose/config/sort_services.pyc
  compose/config/types.py
  compose/config/types.pyc
  compose/config/validation.py
  compose/config/validation.pyc
  compose/const.py
  compose/const.pyc
  compose/container.py
  compose/container.pyc
  compose/errors.py
  compose/errors.pyc
  compose/network.py
  compose/network.pyc
  compose/parallel.py
  compose/parallel.pyc
  compose/progress_stream.py
  compose/progress_stream.pyc
  compose/project.py
  compose/project.pyc
  compose/service.py
  compose/service.pyc
  compose/state.py
  compose/state.pyc
  compose/utils.py
  compose/utils.pyc
  compose/volume.py
  compose/volume.pyc
  docker_compose-1.8.0.dist-info/DESCRIPTION.rst
  docker_compose-1.8.0.dist-info/INSTALLER
  docker_compose-1.8.0.dist-info/METADATA
  docker_compose-1.8.0.dist-info/RECORD
  docker_compose-1.8.0.dist-info/WHEEL
  docker_compose-1.8.0.dist-info/entry_points.txt
  docker_compose-1.8.0.dist-info/metadata.json
  docker_compose-1.8.0.dist-info/pbr.json
  docker_compose-1.8.0.dist-info/top_level.txt
Entry-points:
  [console_scripts]
  docker-compose=compose.cli.main:main

I have tried the following - but still get the same error:

$ chmod +x /home/username/.local/bin/docker-compose
$ chmod +x /home/username/.local/lib/python2.7/site-packages
Where is docker-compose installed? Did you install it via a package (in which case, dpkg -s docker-compose would verify that), or did you install via some other mechanism?
The same error, command not found? Did you try to sudo /home/user/.local/bin/docker-compose ... ?
As I see, docker-compose is installed in local path which will not be accessible to sudo use sudo "PATH=$PATH" docker-compose if /home/user/.local/bin is already in your user path, else use sudo "PATH=$PATH:/home/user/.local/bin" docker-compose. (updated answer)

J
J. Scott Elblein

On Ubuntu 16.04

Here's how I fixed this issue: Refer Docker Compose documentation

sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose

After you do the curl command , it'll put docker-compose into the

/usr/local/bin

which is not on the PATH. To fix it, create a symbolic link:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

And now if you do: docker-compose --version

You'll see that docker-compose is now on the PATH


addition of symbolic fixed it
seems a lot of work, I just ran this command to fix the problem: > sudo apt install docker-compose
March 2022 - use this for linux sudo curl -L github.com/docker/compose/releases/download/v2.3.4/… -o /usr/local/bin/docker-compose
FrankyHollywood 's solution worked for me
l
larsks

The output of dpkg -s ... demonstrates that docker-compose is not installed from a package. Without more information from you there are at least two possibilities:

docker-compose simply isn't installed at all, and you need to install it. The solution here is simple: install docker-compose. docker-compose is installed in your $HOME directory (or other location not on root's $PATH). There are several solution in this case. The easiest is probably to replace: sudo docker-compose ... With: sudo `which docker-compose` ... This will call sudo with the full path to docker-compose. You could alternatively install docker-compose into a system-wide directory, such as /usr/local/bin.


I want to particularly thank you for including the quick easy solution using the back tic single quotes 'sudo which docker-compose . . . ' Works great with the back tic, fails with anything else...
P
Pratik

If you have tried installing via the official docker-compose v1 page, where you need to download the binary using curl:

sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Then do not forget to add executable flag to the binary:

sudo chmod +x /usr/local/bin/docker-compose

If docker-compose is installed using python-pip

sudo apt-get -y install python-pip
sudo pip install docker-compose

try using pip show --files docker-compose to see where it is installed.

If docker-compose is installed in user path, then try:

sudo "PATH=$PATH" docker-compose

As I see from your updated post, docker-compose is installed in user path /home/user/.local/bin and if this path is not in your local path $PATH, then try:

sudo "PATH=$PATH:/home/user/.local/bin" docker-compose

There are multiple ways to install it, pip is one, but it could also be downloaded as a binary.
I used pip to install compose.
FYI, it is OK to pip install docker-compose without sudo - this will just install for your local user under $HOME/.local/bin - afterwards, just update your $PATH in .bashrc/.zshrc/etc to include it: export PATH=$HOME/.local/bin:$PATH
P
Pratik

I have same issue , i solved issue :

Following installs Docker Compose v1:

step-1 : download docker-compose using following command.

     1. sudo su

     2. sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

Step-2 : Run command

    chmod +x /usr/local/bin/docker-compose

Step-3 : Check docker-compose version

     docker-compose --version

thanks, after a lot of searching this was the only that helped me
J
J. Scott Elblein

I will leave this here as a possible fix, worked for me at least and might help others. Pretty sure this would be a linux only fix.

I decided to not go with the pip install and go with the github version (option one on the installation guide).

Instead of placing the copied docker-compose directory into /usr/local/bin/docker-compose from the curl/github command, I went with /usr/bin/docker-compose which is the location of Docker itself and will force the program to run in root. So it works in root and sudo but now won't work without sudo so the opposite effect which is what you want to run it as a user anyways.


As well as moving docker-compose to the other location, it helps to add a symbolic link: ln -s /usr/bin/docker-compose /usr/local/bin/docker-compose
@VinceBowdren I think you meant the other way around: ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
S
Sasha Shpota

If docker-compose is installed for your user but not installed for root user and if you need to run it only once and forget about it afterwords perform the next actions:

Find out path to docker-compose: which docker-compose

Run the command specifying full path to docker-compose from the previous command, eg: sudo /home/your-user/your-path-to-compose/docker-compose up


B
Brivaldo Junior

Or, just add your binary path into the PATH. At the end of the bashrc:

... 
export PATH=$PATH:/home/user/.local/bin/

save the file and run:

source .bashrc

and the command will work.


M
MD Nasirul Islam

docker-compose is not installed. Please try to install it first from their official documentation
Whenever this type of error occurs please try to verify the installation of the apps by typing which command_name it will search for the executables and show you the location.


A
Alon212

Had to delete a large log file then restart docker-compose for the space to clear up. I used a script shell that cron runs once a day:

rm /var/log/cron/log_prodTEST.log
cd /opt/test/metrics
/usr/local/bin/docker-compose up --build --force-recreate -d -T

Apperntly by using the full path to docker-compose, I could use it inside the corn shell