简体   繁体   English

sudo:docker-compose:找不到命令

[英]sudo: docker-compose: command not found

I am trying to run docker-compose using sudo.我正在尝试使用 sudo 运行 docker-compose。

I have both docker and docker-compose installed on Ubuntu 16.01.我在 Ubuntu 16.01 上同时安装了 docker 和 docker-compose。

Due to an error while trying to download compose using curl, I ended up installing it using pip.由于尝试使用 curl 下载 compose 时出错,我最终使用 pip 安装它。

Docker version 1.12.0, build 8eab29e docker-compose version 1.8.0, build 94f7016 Docker 版本 1.12.0,构建 8eab29e docker-compose 版本 1.8.0,构建 94f7016

Yet, when I try to run docker-compose with sudo I get the following (using sudo with docker is fine)然而,当我尝试使用 sudo 运行 docker-compose 时,我得到以下信息(将 sudo 与 docker 一起使用很好)

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.我一直在声称未安装的同一台计算机上使用 docker-compose。

$ 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

On Ubuntu 16.04在 Ubuntu 16.04 上

Here's how I fixed this issue: Refer Docker Compose documentation以下是我解决此问题的方法:请参阅Docker Compose 文档

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

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

After you do the curl command , it'll put docker-compose into the执行 curl 命令后,它会将 docker-compose 放入

/usr/local/bin /usr/local/bin

which is not on the PATH .这不在PATH上。 To fix it, create a symbolic link:要修复它,请创建一个符号链接:

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

And now if you do: docker-compose --version现在如果你这样做: docker-compose --version

You'll see that docker-compose is now on the PATH你会看到 docker-compose 现在在PATH

The output of dpkg -s ... demonstrates that docker-compose is not installed from a package. dpkg -s ...的输出表明docker-compose不是从包中安装的。 Without more information from you there are at least two possibilities:如果没有您提供的更多信息,至少有两种可能性:

  1. docker-compose simply isn't installed at all, and you need to install it. docker-compose 根本没有安装,你需要安装它。

    The solution here is simple: install docker-compose .这里的解决方案很简单:安装docker-compose

  2. docker-compose is installed in your $HOME directory (or other location not on root's $PATH ). docker-compose 安装在您的$HOME目录(或不在根目录$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 .这将使用docker-compose的完整路径调用sudo

    You could alternatively install docker-compose into a system-wide directory, such as /usr/local/bin .您也可以将docker-compose安装到系统范围的目录中,例如/usr/local/bin

If you have tried installing via the official docker-compose v1 page, where you need to download the binary using curl:如果您尝试通过官方 docker-compose v1 页面安装,您需要使用 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如果 docker-compose 是使用 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.尝试使用pip show --files docker-compose查看它的安装位置。

If docker-compose is installed in user path, then try:如果 docker-compose 安装在用户路径中,请尝试:

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:正如我从您更新的帖子中看到的那样,docker-compose 安装在用户路径/home/user/.local/bin中,如果此路径不在您的本地路径$PATH中,请尝试:

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

I have same issue , i solved issue :我有同样的问题,我解决了问题:

Following installs Docker Compose v1:以下安装 Docker Compose v1:

step-1 : download docker-compose using following command.第 1 步:使用以下命令下载 docker-compose。

     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第 2 步:运行命令

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

Step-3 : Check docker-compose version第 3 步:检查 docker-compose 版本

     docker-compose --version

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.很确定这将是一个仅限 linux 的修复程序。

I decided to not go with the pip install and go with the github version (option one on the installation guide).我决定不使用 pip install 而使用 github 版本(安装指南上的选项一)。

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.我没有将复制的 docker-compose 目录从 curl/github 命令放入/usr/local/bin/docker-compose ,而是使用/usr/bin/docker-compose ,这是 Docker 本身的位置,将强制执行程序在根目录下运行。 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.所以它可以在 root 和 sudo 中工作,但现在如果没有sudo就无法工作,所以相反的效果就是你想要以用户身份运行它。

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:如果为您的用户安装了docker-compose ,但没有为root用户安装,并且您只需要运行一次并忘记它,那么执行以下操作:

  • Find out path to docker-compose:找出 docker-compose 的路径:

     which docker-compose
  • Run the command specifying full path to docker-compose from the previous command, eg:运行从上一个命令中指定docker-compose完整路径的命令,例如:

     sudo /home/your-user/your-path-to-compose/docker-compose up

You might be using a deprecated code.您可能正在使用已弃用的代码。 Try writing docker compose instead of docker-compose .尝试编写docker compose而不是docker-compose

There are too many pending edits on Stack Overflow, so I'm submitting a new answer that supplements earlier answers. Stack Overflow 上有太多待处理的编辑,因此我提交了一个新答案来补充之前的答案。

I propose the answer is syntax: docker compose vs docker-compose depending on how you have it installed, which is the same proposed answer by ibrahim shazly on Sep 27, 2022 and Gaurav Kumar Verma on Sep 29, 2022.我建议答案是语法: docker compose vs docker-compose取决于你如何安装它,这与 ibrahim shazly 于 2022 年 9 月 27 日和 Gaurav Kumar Verma 于 2022 年 9 月 29 日提出的答案相同。

Here is an explanation.这是一个解释。 I followed https://docs.docker.com/engine/install/ubuntu/#install-docker-engine to install Docker on Ubuntu 22 LTS.我按照https://docs.docker.com/engine/install/ubuntu/#install-docker-engine在 Ubuntu 22 LTS 上安装 Docker。 Then, I attempted to run docker compose like so:然后,我尝试像这样运行 docker compose:

$ docker-compose up -d myserver
Command 'docker-compose' not found, but can be installed with:
...

As Gaurav Kumar Verma points out, https://docs.docker.com/compose/install/other/ has a disclaimer:正如 Gaurav Kumar Verma 指出的那样, https ://docs.docker.com/compose/install/other/ 有免责声明:

Note that Compose standalone uses the -compose syntax instead of the current standard syntax compose .请注意,Compose standalone 使用-compose语法而不是当前的标准语法compose For example type docker-compose up when using Compose standalone, instead of docker compose up .例如,当使用 Compose standalone 时键入docker-compose up而不是docker compose up

Thus, I ran:因此,我跑了:

$ docker compose up -d myserver

And it ran successfully.它运行成功。

Or, just add your binary path into the PATH.或者,只需将二进制路径添加到 PATH 中。 At the end of the bashrc:在 .bashrc 的末尾:

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

save the file and run:保存文件并运行:

source .bashrc

and the command will work.该命令将起作用。

docker-compose is not installed.未安装docker-compose 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.每当发生此类错误时,请尝试通过键入which command_name来验证应用程序的安装,它将搜索可执行文件并显示位置。

Had to delete a large log file then restart docker-compose for the space to clear up.不得不删除一个大的日志文件,然后重新启动 docker-compose 以清理空间。 I used a script shell that cron runs once a day:我使用了一个 cron 每天运行一次的脚本 shell:

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显然,通过使用 docker-compose 的完整路径,我可以在玉米壳内使用它

On Ubuntu just run在 Ubuntu 上运行

sudo apt install docker-compose sudo apt install docker-compose

This worked on Ubuntu 22*这适用于 Ubuntu 22*

you might try run the code by using docker compose instead of docker-compose if it work you might want to check this link her https://docs.docker.com/compose/install/other/ you might try run the code by using docker compose instead of docker-compose if it work you might want to check this link her https://docs.docker.com/compose/install/other/

Simple, just reinstall the docker-compose.很简单,只需重新安装 docker-compose 即可。 It will fix the issue.它会解决这个问题。

sudo apt install docker-compose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM