误装和删除
最近写了一个 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
来安装。安装完成后又出现了另外一个错误:
root@ubuntu:~/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:
都什么情况!!!
docker-compose version 1.8.0, build unknown
我查了查安装后的版本,显示 build unknown。我第一时间怀疑是版本安装错误,后来打算删除再安装,于是我输入rm /usr/local/bin/docker-compose
来删除 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
- Run this command to download the latest version of Docker Compose:
curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2.Apply executable permissions to the binary:
chmod +x /usr/local/bin/docker-compose
4.Test the installation.
docker-compose
如无意外应该可以正常运行 docker-compose 了。