在ubuntu上安装删除docker-compose的各种坑

误装和删除

最近写了一个app,于是乎打算用docker的image来区分mongodb和FLASK app。在本地创建好了image用docker-compose up是可以完美运行的,但当我将代码放到VPS上就出现以下错误:

The program 'docker-compose' is currently not installed. You can install it by typing:
apt install docker-compose

其实我老早就安装了docker,不知道为啥docker-compose需要另外分开安装,太奇怪了。于是我就安装提示输入apt install docker-compose 来安装。安装完成后又出现了另外一个错误:

[email protected]:~/cnF10# docker-compose up
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

都什么情况!!!

[email protected]:~/cnF10# docker-compose --version
docker-compose version 1.8.0, build unknown

我查了查安装后的版本,显示build unknown。我第一时间怀疑是版本安装错误,后来打算删除再安装,于是我输入rm /usr/local/bin/docker-compose来删除docker-compose,结果:

[email protected]:~/cnF10# rm /usr/local/bin/docker-compose
rm: cannot remove '/usr/local/bin/docker-compose': No such file or directory

google了很多帖子,最后通过下面的命令解决:

ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose

来源:https://github.com/docker/compose/issues/3371

重新安装

经过上面的坑之后,发现不能通过简单的apt来安装,所以我走一趟官网,根据正确步骤安装,最后是成功运行了。

官网:https://docs.docker.com/compose/install/#install-compose

  1. Run this command to download the latest version of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2.Apply executable permissions to the binary:

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

4.Test the installation.

docker-compose --version

如无意外应该可以正常运行docker-compose了。

添加新评论