Usage: docker compose build [SERVICE...] Build or rebuild services Options: --build-arg stringArray Set build-time variables for services. --no-cache Do not use cache when building the image --progress string Set type of progress output (auto, tty, plain, quiet) (default "auto") --pull Always attempt to pull a newer version of the image. -q, --quiet Don't print anything to STDOUT
config
验证文件格式是否正确,正确显示配置,错误显示错误原因
down
停止up命令所启动的容器,并移除网络
1 2 3 4 5 6 7
Stop and remove containers, networks
Options: --remove-orphans Remove containers for services not defined in the Compose file. --rmi string Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all") -t, --timeout int Specify a shutdown timeout in seconds (default 10) -v, --volumes volumes Remove named volumes declared in the volumes section of the Compose file and anonymous volumes attached to containers.
exec
进入指定的容器
1 2 3 4 5 6 7 8 9 10 11
Usage: docker compose exec [options] [-e KEY=VAL...] [--] SERVICE COMMAND [ARGS...] Execute a commandin a running container.
Options: -d, --detach Detached mode: Run commandin the background. -e, --env stringArray Set environment variables --index int index of the container if there are multiple instances of a service [default: 1]. (default 1) -T, --no-TTY docker compose exec Disable pseudo-TTY allocation. By default docker compose exec allocates a TTY. --privileged Give extended privileges to the process. -u, --user string Run the command as this user.(user or uid) -w, --workdir string Path to workdir directory for this command.
images
列出compose文件包含的镜像
1 2 3 4 5 6
Usage: docker compose images [SERVICE...]
List images used by the created containers
Options: -q, --quiet Only display IDs
kill
发送SIGKILL来强制停止服务容器
支持通过-s参数指定发送的信号,默认发送SIGKILL
1 2 3 4 5 6
Usage: docker compose kill [options] [SERVICE...]
Force stop service containers.
Options: -s, --signal string SIGNAL to send to the container. (default "SIGKILL")
Options: -f, --follow Follow log output. --no-color Produce monochrome output. --no-log-prefix Don't print prefix in logs. --since string Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes) --tail string Number of lines to show from the end of the logs for each container. (default "all") -t, --timestamps Show timestamps. --until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
pause
暂停一个容器
1
Usage: docker compose pause [SERVICE...]
port
打印某个容器端口映射的公共端口
选项:
--protocol=proto 指定端口协议,tcp(默认值)或者
udp。
--index=index
如果同一服务存在多个容器,指定命令对象容器的序号(默认为 1)
1 2 3 4 5 6 7
Usage: docker compose port [options] [--] SERVICE PRIVATE_PORT
Print the public port for a port binding.
Options: --index int index of the container if service has multiple replicas (default 1) --protocol string tcp or udp (default "tcp")
ps
列出项目中目前的所有容器
选项:
-q 只打印容器的 ID 信息。
1 2 3 4 5 6 7 8 9 10
Usage: docker compose ps [SERVICE...]
List containers
Options: -a, --all Show all stopped containers (including those created by the run command) --format string Format the output. Values: [pretty | json] (default "pretty") -q, --quiet Only display IDs --services Display services --status stringArray Filter services by status. Values: [paused | restarting | removing | running | dead | created | exited]
pull
拉取服务依赖的镜像
1 2 3 4 5 6 7
Usage: docker compose pull [SERVICE...] Pull service images
Options: --ignore-pull-failures Pull what it can and ignores images with pull failures --include-deps Also pull services declared as dependencies -q, --quiet Pull without printing progress information
push
推送服务依赖的镜像到Docker镜像仓库
1 2 3 4 5 6
Usage: docker compose push [SERVICE...]
Push service images
Options: --ignore-push-failures Push what it can and ignores images with push failures
restart
重启项目中的服务
选项:
-t, --timeout TIMEOUT 指定重启前停止容器的超时(默认为
10 秒)。
1 2 3 4 5 6
Usage: docker compose restart
Restart containers
Options: -t, --timeout int Specify a shutdown timeoutin seconds (default 10)
Options: -f, --force Force the removal of a running container (uses SIGKILL) -l, --link Remove the specified link -v, --volumes Remove anonymous volumes associated with the container
Usage: docker compose run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l KEY=VALUE...] SERVICE [COMMAND] [ARGS...]
Run a one-off command on a service.
Options: -d, --detach Run container in background and print container ID --entrypoint string Override the entrypoint of the image -e, --env stringArray Set environment variables -i, --interactive Keep STDIN open even if not attached. (default true) -l, --label stringArray Add or override a label --name string Assign a name to the container -T, --no-TTY Disable pseudo-noTty allocation. By default docker compose run allocates a TTY --no-deps Don't start linked services. -p, --publish stringArray Publish a container's port(s) to the host. --quiet-pull Pull without printing progress information. --rm Automatically remove the container when it exits --service-ports Run command with the service's ports enabled and mapped to the host. --use-aliases Use the service's network useAliases in the network(s) the container connects to. -u, --user string Run as specified username or uid -v, --volume stringArray Bind mount a volume. -w, --workdir string Working directory inside the container
Options: --abort-on-container-exit Stops all containers if any container was stopped. Incompatible with -d --always-recreate-deps Recreate dependent containers. Incompatible with --no-recreate. --attach stringArray Attach to service output. --attach-dependencies Attach to dependent containers. --build Build images before starting containers. -d, --detach Detached mode: Run containers in the background --exit-code-from string Return the exit code of the selected service container. Implies --abort-on-container-exit --force-recreate Recreate containers even if their configuration and image haven't changed. --no-build Don't build an image, even if it's missing. --no-color Produce monochrome output. --no-deps Don't start linked services. --no-log-prefix Don't print prefix in logs. --no-recreate If containers already exist, don't recreate them. Incompatible with --force-recreate. --no-start Don't start the services after creating them. --quiet-pull Pull without printing progress information. --remove-orphans Remove containers for services not defined in the Compose file. -V, --renew-anon-volumes Recreate anonymous volumes instead of retrieving data from the previous containers. --scale scale Scale SERVICE to NUM instances. Overrides the scale setting in the Compose file if present. -t, --timeout int Use this timeout in seconds for container shutdown when attached or when containers are already running. (default 10) --wait Wait for services to be running|healthy. Implies detached mode.