我已经在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命令(:

其他回答

我正在安装树莓派3,在树莓操作系统上。curl方法没有解析为有效响应。它还说{错误:未找到},我看了一下URL https://github.com/docker/compose/releases/download/1.11.2/docker-compose-Linux-armv7l,它是无效的。我猜那里没有建筑。

这个指南https://github.com/hypriot/arm-compose对我很有用。

sudo apt-get update
sudo apt-get install -y apt-transport-https
echo "deb https://packagecloud.io/Hypriot/Schatzkiste/debian/ jessie main" | sudo tee /etc/apt/sources.list.d/hypriot.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 37BBEE3F7AD95B3F
sudo apt-get update
sudo apt-get install docker-compose

我在debian上,我发现了一些很自然的事情:

apt-get install docker-compose

它做到了 (未测试centos)

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

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.

问候, 亚当

如果你想自动安装docker-compose最新版本,只需运行:

export docker_compose_latest=$(curl -Ls -o /dev/null -w %{url_effective}  https://github.com/docker/compose/releases/latest  | grep -o '[^/]*$')
curl -L "https://github.com/docker/compose/releases/download/${docker_compose_latest}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

它将安装最新版本的docker-compose。正式安装方式需自行获取版本。但是我写了一个脚本,可以自动获取最新版本。

官方文件显示:

如果您为Windows或Mac安装了Docker Desktop/Toolbox,则您需要 已经有Docker Compose!Play-with-Docker实例已经有了 Docker Compose也安装了。如果您使用的是Linux机器,那么您 需要安装Docker Compose。

为此,您需要参考预先存在的Docker安装部分。