我已经在CentOS 7上安装了docker,运行如下命令:

curl -sSL https://get.docker.com/ | sh
systemctl enable docker && systemctl start docker
docker run hello-world

注意:helloworld运行正常,没有问题。

然而,当我试图运行docker-compose (docker-compose。yml存在并且有效)它只在CentOS上给了我错误(Windows版本的docker-compose文件工作良好)

/usr/local/bin/docker-compose: line 1: {error:Not Found}: command not found

当前回答

他们改变了语法。现在它是这样写的:

docker compose [OPTIONS] COMMAND
docker compose ps

现在撰写是插件!但是其他的文档页有旧的语法。 我该如何支持兼容性?!

更新: 如果你运行脚本,它可以得到撰写命令:

# docker-compose.sh
if docker compose version > /dev/null ; then
    echo "docker compose"
else
    echo "docker-compose"
fi

# other.sh
DOCKER_C=$($BASEDIR/docker-compose.sh)
echo "docker command is: $DOCKER_C"

生活在拐杖上,感谢Docker命令(:

其他回答

对于Ubuntu操作系统有很多建议,但我认为最简单的解决方案是创建一个别名。(如果docker compose已经安装)

步骤:

Ls -la在~目录中查看是否有.bash_aliases 如果不直接创建它(触摸,纳米…或者简单地使用gedit) gedit .bash_aliases (以上步骤可以跳过,只需在.bashrc中添加你的别名) 添加别名别名docker-compose="docker compose" 使别名在当前会话中可用:source ~/.bashrc

在Linux上,您可以从GitHub上的Compose存储库发布页面下载Docker Compose二进制文件。按照链接中的说明操作,其中包括在终端上运行curl命令来下载二进制文件。这些分步指导也包括在下面。

1:执行此命令下载Docker Compose当前稳定版本:

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

若要安装不同版本的Compose,请将1.26.2替换为您想使用的Compose版本。

2:应用可执行权限的二进制文件:

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

注意:如果安装后命令docker-compose失败,请检查 你的路。您还可以创建到/usr/bin或任何的符号链接 路径中的其他目录。

以上的解决方案对我不起作用。但我发现这个很管用:

sudo apt-get update -y && sudo apt-get install -y python3-pip python3-dev
sudo apt-get remove docker docker-engine docker.io
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo pip3 install docker-compose
#sudo docker-compose -f docker-compose-profess.yml pull ofw
sudo usermod -a -G docker $USER
sudo reboot

如果你用的是ubuntu, docker compose可以工作,但docker-compose不行,你需要旧的docker-compose语法可用(可能第三方库使用它),你可以通过以下步骤修复它:

docker-compose插件可能安装在/usr/libexec/docker/cli-plugins/docker-compose(确保它是)

创建一个符号链接到它:

sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose

现在docker-compose应该可用了

更新:

如果docker-compose在上述路径中找不到,您可以从您的操作系统的发布页面手动下载它,然后移动下载的文件并使其可执行。

cd ~/Downloads
sudo mv ./docker-compose-* /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

参考上面给出的答案(我没有足够的声誉单独提到单独的解决方案,因此我在这里集体做这些),我想补充一些重要的建议:

docker-compose you can install from the repository (if you have this package in the repository, if not you can adding to system a repository with this package) or download binary with use curl - totourial on the official website of the project - src: https://docs.docker.com/compose/install / docker-compose from the repository is in version 1.8.0 (at least at me). This docker-compose version does not support configuration files in version 3. It only has version = <2 support. Inthe official site of the project is a recommendation to use container configuration in version 3 - src: https://docs.docker.com/compose/compose-file / compose-versioning /. From my own experience with work in the docker I recommend using container configurations in version 3 - there are more configuration options to use than in versions <3. If you want to use the configurations configurations in version 3 you have to do update / install docker-compose to the version of at least 1.17 - preferably the latest stable. The official site of the project is toturial how to do this process - src: https://docs.docker.com/compose/install/ when you try to manually remove the old docker-compose binaries, you can have information about the missing file in the default path /usr/local/bin/docker-compose. At my case, docker-compose was in the default path /usr/bin/docker-compose. In this case, I suggest you use the find tool in your system to find binary file docker-compose - example syntax: sudo find / -name 'docker-compose'. It helped me. Thanks to this, I removed the old docker-compose version and added the stable to the system - I use the curl tool to download binary file docker-compose, putting it in the right path and giving it the right permissions - all this process has been described in the posts above.

问候, 亚当