安装

通过 wgetcURL 下载:

# 先获取最新版本
VERSION=$(curl -sL "https://api.github.com/repos/docker/compose/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
 
# wget
wget https://github.com/docker/compose/releases/download/$VERSION/docker-compose-$(uname -s)-$(uname -m) -O /usr/local/bin/docker-compose
 
# curl
curl -SL https://github.com/docker/compose/releases/download/$VERSION/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
 
# 添加权限
chmod +x /usr/local/bin/docker-compose

最新版本也可以从 Releases · docker/compose 查看。

: 不要用 pip 方式安装,版本太老了。

命令

  • down: 停止容器,并移除网络
  • start: 启动容器
  • restart: 重启服务
  • stop: 停止容器,但不删除
  • exec: 进入指定容器
  • images: 列出包含的镜像
  • ps: 查看项目中所有容器
  • pull: 拉取依赖的镜像
  • logs: 查看日志

up

下载、构建镜像、创建/启动服务。如果已在运行,up 命令将会停止容器,重新创建挂载的卷。

  • -d:后台运行
  • —build:重新构建(不会删除原有镜像)
  • —force-recreate:强制重新创建容器 (需要更新容器或者配置时使用)
  • —remove-orphans:清理配置中已经删除的服务
  • —no-recreate:仅启动已处于停止状态的容器

参数

  • restart: always: 开机自动运行

参考