Introduction and use of docker-compose command [Official English document translation] [Additional case]

Fu Tao Gong Qing breeze has passed through the ages, so who else would dare to call him a man?
Insert picture description here

Introduction

- : Indicates an abbreviation
: Indicates the full name

command

docker-compose ps

Lists containers.
Show all containers

original:

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

Options:
    -q, --quiet          Only display IDs
    --services           Display services
    --filter KEY=VAL     Filter services by a property
    -a, --all            Show all stopped containers (including those created by the run command)

translation:

 使用方法:ps [选项] [服务…]

选项:
    -q, --quiet          只显示所有容器的ID
    --services           显示所有服务
    --filter KEY=VAL     通过属性筛选服务
    -a, --all            显示所有已停止的容器(包括由run命令创建的容器)

Case:

Run the container beforehand:
[root@VM-0-11-centos tomcat]# ls
docker-compose.yml
[root@VM-0-11-centos tomcat]# docker-compose up -d

  1. No options
[root@VM-0-11-centos tomcat]# docker-compose ps
 Name        Command       State           Ports         
---------------------------------------------------------
tomcat   catalina.sh run   Up      0.0.0.0:8080->8080/tcp
  1. -q, --quiet
[root@VM-0-11-centos tomcat]# docker-compose ps -q
f4dd5f5aefb284907de492e0aef881b4e6a5ec51fb5437850ce6cbdaf672ee4a

[root@VM-0-11-centos tomcat]# docker-compose ps --quiet
f4dd5f5aefb284907de492e0aef881b4e6a5ec51fb5437850ce6cbdaf672ee4a
  1. –filter KEY=VAL

  2. -a,–all

[root@VM-0-11-centos tomcat]# docker-compose ps -a
 Name         Command       State           Ports         
----------------------------------------------------------
tomcat2   catalina.sh run   Up      0.0.0.0:8082->8080/tcp

[root@VM-0-11-centos tomcat]# docker-compose ps --all
 Name         Command       State           Ports         
----------------------------------------------------------
tomcat2   catalina.sh run   Up      0.0.0.0:8082->8080/tcp

docker-compose up

Builds, (re)creates, starts, and attaches to containers for a service. Builds, (re)creates, starts, and attaches to containers for a service
.

original:

Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...]

Options:
    -d, --detach               Detached mode: Run containers in the background,
                               print new container names. Incompatible with
                               --abort-on-container-exit.
    --no-color                 Produce monochrome output.
    --quiet-pull               Pull without printing progress information
    --no-deps                  Don't start linked services.
    --force-recreate           Recreate containers even if their configuration
                               and image haven't changed.
    --always-recreate-deps     Recreate dependent containers.
                               Incompatible with --no-recreate.
    --no-recreate              If containers already exist, don't recreate
                               them. Incompatible with --force-recreate and 
                               --renew-anon-volumes.
    --no-build                 Don't build an image, even if it's missing.
    --no-start                 Don't start the services after creating them.
    --build                    Build images before starting containers.
    --abort-on-container-exit  Stops all containers if any container was
                               stopped. Incompatible with --detach.
    --attach-dependencies      Attach to dependent containers.
    -t, --timeout TIMEOUT      Use this timeout in seconds for container
                               shutdown when attached or when containers are
                               already running. (default: 10)
    -V, --renew-anon-volumes   Recreate anonymous volumes instead of retrieving
                               data from the previous containers.
    --remove-orphans           Remove containers for services not defined
                               in the Compose file.
    --exit-code-from SERVICE   Return the exit code of the selected service
                               container. Implies --abort-on-container-exit.
    --scale SERVICE=NUM        Scale SERVICE to NUM instances. Overrides the
                               `scale` setting in the Compose file if present.

translation:

使用方法: up [选项] [--scale SERVICE=NUM...] [SERVICE...]

选项:
    -d, --detach               附加模式:在后台运行容器,打印新的容器名称。不兼容——abort-on-container-exit。
    --no-color                 以单色输出
    --quiet-pull               拉取而不打印进度信息
    --no-deps                  不启动链接服务
    --force-recreate           即使容器的配置和镜像没有改变, 容器也要重新被创建
    --always-recreate-deps     重新创建容器的依赖,不兼容——no-recreate
    --no-recreate              如果容器已经存在,不要重新创建它们。-force-和-renew-anon-volumes不兼容。
    --no-build                 不要构建一个镜像,即使它缺失
    --no-start                 创建服务后不要启动它们
    --build                    在启动容器之前构建镜像
    --abort-on-container-exit  如果任何容器被停止,则停止所有容器。与--detach不兼容
    --attach-dependencies      附加到依赖容器
    -t, --timeout TIMEOUT      当附加容器或容器已经在运行时,使用此超时(以秒为单位)用于关闭容器。(默认值:10)
    -V, --renew-anon-volumes   重新创建匿名数据卷,而不是从以前的容器检索数据
    --remove-orphans           删除Compose文件中未定义的服务容器。
    --exit-code-from SERVICE   返回所选服务容器的退出代码。意味着——abort-on-container-exit。
    --scale SERVICE=NUM        将服务扩展到NUM实例。如果存在,将覆盖Compose文件中的“scale”设置。

Case:

  1. No options

Insert picture description here

  1. —no-color
    Insert picture description here

docker-compose down

Stops containers and removes containers, networks, volumes, and images created by up.
Stop the containers and delete the containers, networks, data volumes, and images created by up .

original:

Usage: down [options]

Options:
    --rmi type              Remove images. Type must be one of:
                              'all': Remove all images used by any service.
                              'local': Remove only images that don't have a
                              custom tag set by the `image` field.
    -v, --volumes           Remove named volumes declared in the `volumes`
                            section of the Compose file and anonymous volumes
                            attached to containers.
    --remove-orphans        Remove containers for services not defined in the
                            Compose file
    -t, --timeout TIMEOUT   Specify a shutdown timeout in seconds.
                            (default: 10)

translation:

用法:down[选项]
选项:
    --rmi type              删除镜像。类型必须是以下之一:
                           'all':删除任何服务使用的所有镜像。
                           'local':只删除没有' image '字段设置的自定义标签的图像。
    -v, --volumes           删除在Compose文件的' volumes '部分声明的命名卷和附加到容器上的匿名卷。
    --remove-orphans        删除在Compose文件中未定义的服务容器
    -t, --timeout TIMEOUT   指定关机超时时间(以秒为单位)( 默认值:10)

Case:

  1. –rmi type
[root@VM-0-11-centos tomcat]# docker-compose down --rmi all
Stopping tomcat2 ... done
Removing tomcat2 ... done
Removing network tomcat_default
Removing image tomcat:7.0.57
[root@VM-0-11-centos tomcat]# docker-compose ps
Name   Command   State   Ports
------------------------------
  1. No options
[root@VM-0-11-centos tomcat]# docker-compose down
Stopping tomcat2 ... done
Removing tomcat2 ... done
Removing network tomcat_default
[root@VM-0-11-centos tomcat]# docker-compose ps
Name   Command   State   Ports
------------------------------

docker-compose logs

Displays log output from services. Displays log output from services
.

original:

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

Options:
    --no-color          Produce monochrome output.
    -f, --follow        Follow log output.
    -t, --timestamps    Show timestamps.
    --tail="all"        Number of lines to show from the end of the logs
                        for each container.

translation:

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

Options:
    --no-color          产生单色输出。
    -f, --follow        遵循日志输出
    -t, --timestamps    显示时间戳。
    --tail="all"       从每个容器的日志末尾开始显示行数。

Case:

  1. No options

Insert picture description here

  1. –no-color

Insert picture description here

  1. -t, --timestamps

Insert picture description here

  1. –tail=“all”

Insert picture description here

docker-compose build

Services are built once and then tagged, by default as project_service. For example, composetest_db. If the Compose file specifies an image name, the image is tagged with that name, substituting any variables beforehand. See variable substitution.
If you change a service's Dockerfile or the contents of its build directory, run docker-compose build to rebuild it. The
service is only built once, and then marked, the default is project_service. For example, composetest_db. If the Compose file specifies an image name, the image will be marked with that name and any variables will be replaced in advance. See variable substitution.
If you change the contents of a service's Dockerfile or its build directory, run docker-compose build to rebuild it.

original:

Usage: build [options] [--build-arg key=val...] [SERVICE...]

Options:
    --build-arg key=val     Set build-time variables for services.
    --compress              Compress the build context using gzip.
    --force-rm              Always remove intermediate containers.
    -m, --memory MEM        Set memory limit for the build container.
    --no-cache              Do not use cache when building the image.
    --no-rm                 Do not remove intermediate containers after a successful build.
    --parallel              Build images in parallel.
    --progress string       Set type of progress output (`auto`, `plain`, `tty`).
    --pull                  Always attempt to pull a newer version of the image.
    -q, --quiet             Don't print anything to `STDOUT`.

translation:

使用方法: build [选项] [--build-arg key=val...] [SERVICE...]

选项:
    --build-arg key=val     为服务设置构建时变量。
    --compress              使用gzip压缩构建上下文。
    --force-rm              始终移除中间容器
    -m, --memory MEM        为构建容器设置内存限制。
    --no-cache              在构建镜像时不要使用缓存。
    --no-rm                 在成功构建之后,不要删除中间容器。
    --parallel              并行构建映像。
    --progress string       设置进度输出类型(' auto '' plain '' tty ')。
    --pull                  总是尝试拉出一个新版本的镜像。
    -q, --quiet             不要打印任何东西到' STDOUT '

Case:

  1. List item

  2. List item

  3. List item

  4. List item

  5. List item

docker-compose port

Prints the public port for a port binding. Prints the public port for a port binding
.

original:

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]

translation:

使用方法:port [选项] SERVICE PRIVATE_PORT

选项:
    --protocol=proto  tcp或udp[默认值:tcp]
    --index=index     如果服务有多个实例,则为容器索引[默认值:1]

Case:

  1. No options

  2. –protocol=proto

  3. –index=index

docker-compose rm


Removes stopped service containers. Removes stopped service containers.

original:

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

Options:
    -f, --force   Don't ask to confirm removal
    -s, --stop    Stop the containers, if required, before removing
    -v            Remove any anonymous volumes attached to containers
    -a, --all     Deprecated - no effect.

translation:

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

Options:
    -f, --force   强制删除
    -s, --stop    如果需要,在删除容器之前,停止容器
    -v            删除任何附加到容器上的匿名数据卷
    -a, --all     弃用 - no effect.

Case:

  1. -f, --force

  2. -s, --stop

[root@VM-0-11-centos tomcat]# docker-compose rm -s
Stopping tomcat2 ... done
Going to remove tomcat2
Are you sure? [yN] y
Removing tomcat2 ... done
  1. -v

  2. -a, --all

docker-compose restart

Restarts all stopped and running services. Restarts all stopped and running services
.

original:

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

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

translation:

使用方法: restart [选项] [SERVICE...]

选项:
  -t, --timeout TIMEOUT      指定关机超时时间(以秒为单位)(默认值:10)

Case:

  1. No options
[root@VM-0-11-centos tomcat]# docker-compose ps
 Name         Command       State           Ports         
----------------------------------------------------------
tomcat2   catalina.sh run   Up      0.0.0.0:8082->8080/tcp
[root@VM-0-11-centos tomcat]# docker-compose restart
Restarting tomcat2 ... done
[root@VM-0-11-centos tomcat]# docker-compose ps
 Name         Command       State           Ports         
----------------------------------------------------------
tomcat2   catalina.sh run   Up      0.0.0.0:8082->8080/tcp
  1. -t, --timeout TIMEOUT
[root@VM-0-11-centos tomcat]# docker-compose restart -t 2
Restarting tomcat2 ... done

docker-compose start

Starts existing containers for a service. Starts existing containers for a service
.

original:

Usage: start [SERVICE...]

translation:

使用方法: start [SERVICE...]

Case:

  1. List item

  2. List item

  3. List item

  4. List item

  5. List item

docker-compose config

Validate and view the Compose file. Validate and view the Compose file
.

original:

Usage: config [options]

Options:
    --resolve-image-digests  Pin image tags to digests.
    --no-interpolate         Don't interpolate environment variables.
    -q, --quiet              Only validate the configuration, don't print
                             anything.
    --services               Print the service names, one per line.
    --volumes                Print the volume names, one per line.
    --hash="*"               Print the service config hash, one per line.
                             Set "service1,service2" for a list of specified services
                             or use the wildcard symbol to display all services.

translation:

Usage: config [options]

Options:
    --resolve-image-digests  Pin镜像标签到摘要。
    --no-interpolate         不插入环境变量。
    -q, --quiet              只验证配置,不打印任何东西。
    --services               打印服务名,每行一个。
    --volumes                打印数据卷名,每行一个。
    --hash="*"               打印服务配置散列,每行一个。为指定的服务列表设置“service1,service2”,或使用通配符来显示所有服务。

Case:

  1. No options

  2. –resolve-image-digests

  3. -q, --quiet

  4. –services

  5. –volumes

  6. –hash="*"

docker-compose stop

Stops running containers without removing them. They can be started again with docker-compose start.
Stop running containers without removing them. They can be restarted via docker-compose start.

original:

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

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

translation:

使用方法: stop [选项] [SERVICE...]

选项:
  -t, --timeout TIMEOUT      指定关机超时时间(以秒为单位)(默认值:10)

Case:

  1. List item

  2. List item

  3. List item

  4. List item

  5. List item

docker-compose kill

Forces running containers to stop by sending a SIGKILL signal. Optionally the signal can be passed, for example: Forces running containers to stop by sending a SIGKILL signal
. Optional signals can be passed, for example:
docker-compose kill -s SIGINT

original:

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

Options:
    -s SIGNAL         SIGNAL to send to the container.
                      Default signal is SIGKILL.

translation:

使用方法: kill [选项] [SERVICE...]

选项:
    -s SIGNAL         发送信号给容器。默认信号是SIGKILL。

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

original:

translation:

Case:

Guess you like

Origin blog.csdn.net/qq_43073558/article/details/112916788