深色模式
Docker Compose 命令
查看帮助
输入:
sh
docker compose --help
得到:
Usage: docker compose [OPTIONS] COMMAND
Docker Compose
Options:
--ansi string Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
--compatibility Run compose in backward compatibility mode
--env-file string Specify an alternate environment file.
-f, --file stringArray Compose configuration files
--profile stringArray Specify a profile to enable
--project-directory string Specify an alternate working directory
(default: the path of the Compose file)
-p, --project-name string Project name
Commands:
build Build or rebuild services
convert Converts the compose file to platform's canonical format
cp Copy files/folders between a service container and the local filesystem
create Creates containers for a service.
down Stop and remove containers, networks
events Receive real time events from containers.
exec Execute a command in a running container.
images List images used by the created containers
kill Force stop service containers.
logs View output from containers
ls List running compose projects
pause Pause services
port Print the public port for a port binding.
ps List containers
pull Pull service images
push Push service images
restart Restart containers
rm Removes stopped service containers
run Run a one-off command on a service.
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show the Docker Compose version information
Run 'docker compose COMMAND --help' for more information on a command.
命令选项:
--env-file
-f
查看单个命令的帮助
语法:
sh
docker compose COMMAND --help
🌰,输入:
sh
docker compose up --help
得到:
Usage: docker compose up [SERVICE...]
Create and start containers
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.
常用的命令
docker compose up
启动服务:
docker compose up -d [service]
先重新构建镜像,再启动服务:
docker compose up -d --build [service]