语法:
Define and run multi-container applications with Docker.

Usage:
  docker-compose [-f=<arg>...] [options] [COMMAND] [ARGS...]
  docker-compose -h|--help

Options:
  -f, --file FILE             Specify an alternate compose file (default: docker-compose.yml)
  -p, --project-name NAME     Specify an alternate project name (default: directory name)
  --verbose                   Show more output
  -v, --version               Print version and exit
  -H, --host HOST             Daemon socket to connect to

--tls                       Use TLS; implied by --tlsverify
  --tlscacert CA_PATH         Trust certs signed only by this CA
  --tlscert CLIENT_CERT_PATH  Path to TLS certificate file
  --tlskey TLS_KEY_PATH       Path to TLS key file
  --tlsverify                 Use TLS and verify the remote
  --skip-hostname-check       Don't check the daemon's hostname against the name specified
                              in the client certificate (for example if your docker host
                              is an IP address)

Commands:
  build              Build or rebuild services
  config             Validate and view the compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  help               Get help on a command
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pulls service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information

-f   指定docker-compose.xml文件,默认是 docker-compose.xml  ,  当一条命令有多个-f参数时,会做替换操作
-p  指定docker-compose的项目目录,也就是docker-compose.xml文件的存储目录
CLI Environment Variables
Usage: build [options] [SERVICE...]

Options:

--force-rm  Always remove intermediate containers.
--no-cache  Do not use cache when building the image.
--pull      Always attempt to pull a newer version of the image.
当修改dockerfile或者docker-compose时,运行docker-compose build 重建镜像。  生成镜像后,可使用docker-compose up启动

config

Usage: config [options]

--quiet     只验证配置,不输出。
当配置正确时,不输出任何内容,当文件配置错误,输出错误信息。
--services      打印服务名,一行一个
验证和查看compose文件配置。

create

为服务创建容器.只是单纯的create,还需要使用start启动compose

Usage: create [options] [SERVICE...]

Options:
   
--force-recreate       重新创建容器,即使他的配置和镜像没有改变,不兼容--no-recreate参数
.
不兼容--force-recreate参数
   
--no-build             不创建镜像,即使缺失.
   
--build                创建容器前,生成镜像.
down
Usage: down [options]

Options:
   
--rmi type          删除镜像,类型必须是:
                        'all': 删除compose文件中定义的所以镜像.
                        'local': 删除镜像名为空的镜像
--volumes
      删除卷

 
                      attached to containers.
    --remove-orphans    Remove containers for services not defined in the

file
停止和删除容器、网络、卷、镜像,这些内容是通过docker-compose up命令创建的.  默认值删除 容器 网络,可以通过指定 rmi volumes参数删除镜像和卷

events

Usage: events [options] [SERVICE...]

Options:
    --json      输出事件日志,json格式
输出docker-compose 事件的日志,当执行docker-compose命令操作时,docker-compose even命令就会监控日志:
{
    "service": "web",
    "event": "create",
    "container": "213cf75fc39a",
    "image": "alpine:edge",
    "time": "2015-11-20T18:01:03.615550",
}

exec

Usage: exec [options] SERVICE COMMAND [ARGS...]

Options:
-d                分离模式,后台运行命令.
--privileged      获取特权.
--user USER       指定运行的用户.
-T                禁用分配TTY. By default `docker-compose exec`

                  分配 a TTY.
--index=index     当一个服务拥有多个容器时,可通过该参数登陆到该服务下的任何服务,例如:docker-compose exec --index=1 web /bin/bash ,web服务中包含多个容器
of a service [default: 1]
和docker exec命令功能相同,可以通过service name登陆到容器中
e.g. docker-compose
exec web sh
 

kill

Usage: kill [options] [SERVICE...]

Options:
-s SIGNAL         向容器发送信号. 默认是SIGKILL.
通过发送 SIGKILL 信号来强制停止服务容器。支持通过参数来指定发送的信号:
$ docker-compose kill -s SIGINT

logs

Usage: logs [options] [SERVICE...]

Options:

--no-color          单色输出,不显示其他颜.
--follow     
  跟踪日志输出,就是可以实时查看日志
--timestamps 
  显示时间戳
--tail            
 从日志的结尾显示,--tail=200
显示日志输出.

pause

Usage: pause [SERVICE...]
暂停容器服务. docker-compose pause  暂停所有服务. docker-compose pause web,之后暂停web服务的容器。

unpause

Usage:
unpause [SERVICE...]
恢复容器服务. docker-compose unpause  恢复所有服务. docker-compose unpause web,之后恢复web服务的容器。

port

Usage: port [options] SERVICE PRIVATE_PORT

Options:
--protocol=proto  tcp or udp [default: tcp]
--index=index     index of the container if there are multiple
                  instances of a service [default: 1]

输出服务的共有端口.
# docker-compose port web 8080   -- 8080为容器内部端口
0.0.0.0:8884

ps

Usage: ps [options] [SERVICE...]

Options:
-q    只显示ID

显示容器. 默认显示name、command、state、ports

pull

Usage: pull [options] [SERVICE...]

Options:
--ignore-pull-failures  忽略pull失败的镜像,继续pull其他镜像.
pull compose文件中所指明的镜像.

push

Usage: push [options] [SERVICE...]

Options:

push-failures 
忽略错误.
push compose文件中所指明的镜像

restart

Usage: restart [options] [SERVICE...]

Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds. (default: 10)
Restarts services.

rm

Usage: rm [options] [SERVICE...]

Options:

--force   Don't ask to confirm removal
    -v            期初加载到容器的任何匿名卷

 
  -a, --all     Also remove one-off containers created by

                  docker-compose run
Removes stopped service containers. 如果服务在运行,需要先docker-compose stop 停止容器

By default, anonymous volumes attached to containers will not be removed. You can override this with Docker
volume ls
.

Any data which is not in a volume will be lost.

run

Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]

.
-e KEY=VAL            设置环境变量参数,可以使用多次
--user="" 
       指定运行的用户
--no-deps 
           不启动link服务,只启动run的服务.
--rm 
                运行后删除容器,后台运行模式除外(-d).
p, --publish=[] 
    开放端口
--service-ports
      compose文件中配置什么端口,就映射什么端口.

                  禁用TTY.
--workdir=""
     设置工作目录

启动web服务器,并执行bash命令.

$ docker-compose run web bash
根据compose配置文件制定的端口,映射到主机:
$ docker-compose run --service-ports web python manage.py shell
指定端口映射到主机:
$ docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
link db容器:
$ docker-compose run db psql -h db -U docker

不linke容器,单独启动指定容器:

$ docker-compose run --no-deps web python manage.py shell

scale

Usage: scale [SERVICE=NUM...]
设置服务的个数.
$ docker-compose scale web=2 worker=

start

Usage: start [SERVICE...]
启动服务.

stop

Usage: stop [options] [SERVICE...]

Options:

default: 10).
停止容器.

up

Usage: up [options] [SERVICE...]

Options:
    -d                         后台运行,输出容器的名字.
                               Incompatible with --abort-on-container-exit.

   
--no-color                  单色输出.
 
  --no-deps                  不启动link服务.
   
--force-recreate           强制重新创建compose服务,即使没有任何改变。重新创建后启动容器
 
                             Incompatible with --no-recreate.
   
--no-recreate               如果容器已经存在,不重新创建.

 
                             Incompatible with --force-recreate.

   
--no-build                 不创建重启,即使镜像不存在.
   
--build                    重新创建镜像,然后生成容器.

 
  --abort-on-container-exit  任何容器停止,自动停止所有容器.

                               Incompatible with -d.
--timeout TIMEOUT
     超时时间. (default: 10)
   
--remove-orphans           移除compose文件中未定义服务的容器

Docker-compose命令详解的更多相关文章

  1. 附003.Docker Compose命令详解

    一 Docker Compose命令格式 Usage: docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...] docker- ...

  2. 附005.Docker Compose文件详解

    一 Docker Compose文件简介 compose文件使用yml格式,主要分为了四个区域: version:用于指定当前docker-compose.yml语法遵循哪个版本 services:服 ...

  3. Docker常用命令详解

    docker ps 查看当前正在运行的容器 docker ps -a 查看所有容器的状态 docker start/stop id/name 启动/停止某个容器 docker attach id 进入 ...

  4. Docker Compose配置文件详解(V3)

    Docker Compose配置文件是Docker Compose的核心,用于定义服务.网络和数据卷.格式为YAML,默认路径为./docker-compose.yml,可以使用.yml或.yaml扩 ...

  5. docker基础命令详解

    Commands: attach    Attach to a running container build     Build an image from a Dockerfile commit  ...

  6. 谁用光了磁盘?Docker System命令详解

    译者按: Docker镜像,容器,数据卷以及网络都会占用主机的磁盘空间,这样的话,磁盘很容易就会被用完.这篇博客介绍了一个简单的解决方案 - Docker System命令. 原文: What's e ...

  7. Docker Compose 配置文件详解

    先来看一份 docker-compose.yml 文件,不用管这是干嘛的,只是有个格式方便后文解说: version: '2' services: web: image: dockercloud/he ...

  8. Docker Compose文件详解 V2

    Compose file reference 语法: web:      build: ./web      ports:      - "5000:5000"      volu ...

  9. Docker dockerfile命令详解

    docker-file 官网文档:https://docs.docker.com/v17.09/engine/reference/builder/ 制作Dockerfile为Docker入门学习的第一 ...

  10. Docker(12)- docker run 命令详解

    如果你还想从头学起 Docker,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1870863.html 作用 创建一个新的容器并运行一个 ...

随机推荐

  1. codeforces 519E A and B and Lecture Rooms LCA倍增

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Prac ...

  2. AngularJS $http

    $http 是 AngularJS 中的一个核心服务,用于读取远程服务器的数据.在服务器上读取数据: <div ng-app="myApp" ng-controller=&q ...

  3. 后缀数组 SPOJ 694 Distinct Substrings

    题目链接 题意:给定一个字符串,求不相同的子串的个数 分析:我们能知道后缀之间相同的前缀的长度,如果所有的后缀按照 suffix(sa[0]), suffix(sa[1]), suffix(sa[2] ...

  4. BFS(八数码) POJ 1077 || HDOJ 1043 Eight

    题目传送门1 2 题意:从无序到有序移动的方案,即最后成1 2 3 4 5 6 7 8 0 分析:八数码经典问题.POJ是一次,HDOJ是多次.因为康托展开还不会,也写不了什么,HDOJ需要从最后的状 ...

  5. Python学习笔记02

      元组:圆括号的,不能进行赋值操作,即不可更改. 列表:方括号的,可以修改. 访问:均使用下标访问   # 元组是一个静态列表,初始化之后就不可以修改,可以试任意类型 tuple1 = ('a st ...

  6. js事件绑定细节说明

    javascript绑定事件: 经常用jQuery去写,时间长了对原生态的js事件绑定的知识会慢慢淡化或者遗忘了,必须翻出来再次总结,今天再次把js原生态事件的处理做个总结. 从最初开始,谁刚接触ja ...

  7. Visual Studio: 暂时?绕过 fatal error C1083: Cannot open precompiled header file

    可以使用右键点击项目工程中的该cpp文件,选择setting,在c/c++栏,选择PreCompiled headers,然后设置第一选项,选择不使用预编译头.

  8. iOS数据持久化文件读写之偏好设置

    很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能.每个应用都有个NSUserDefaults实例,通过它来存取偏好设置.比如, ...

  9. BZOJ3567 : AABB

    考虑以块大小为$32$将序列分块,设$s[i][j]$表示前$i$块和前$j$块矩形相交的对数,$f[i][j]$表示矩形$i$和前$j$块的相交个数. 如果矩形$i$和$j$相交,那么有: $x_1 ...

  10. [转]基于gulp和webpack的前端工程化

    本文样例代码 :https://github.com/demohi/learning-gulp 本文主要简单介绍一下基于gulp和webpack的前端工程化. 技术栈 React.js reFlux ...