?
本文檔使用 PHP中文網(wǎng)手冊 發(fā)布
此頁面提供docker-compose
命令的使用信息。
您也可以通過docker-compose --help
從命令行運行來查看此信息。
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 --no-ansi Do not print ANSI control characters -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) --project-directory PATH Specify an alternate working directory (default: the path of the Compose file)Commands: build Build or rebuild services bundle Generate a Docker bundle from the Compose file 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 exec Execute a command in a running container help Get help on a command images List images kill Kill containers logs View output from containers 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 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 top Display the running processes unpause Unpause services up Create and start containers version Show the Docker-Compose version information
您可以使用Docker Compose二進制,docker-compose [-f <arg> ...] [options] [COMMAND] [ARGS ...]在Docker容器中構(gòu)建和管理多個服務(wù)。
-f
指定名稱和一個或多個文件撰寫路徑使用該-f
標志來指定Compose配置文件的位置。
您可以提供多個-f
配置文件。當您提供多個文件時,Compose將它們組合成單個配置。撰寫按您提供文件的順序構(gòu)建配置。后續(xù)文件將覆蓋并添加到其前任。
例如,請考慮以下命令行:
$ docker-compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db
該docker-compose.yml
文件可能會指定一項webapp
服務(wù)。
webapp: image: examples/web ports: - "8000:8000" volumes: - "/data"
如果docker-compose.admin.yml
也指定了這個相同的服務(wù),任何匹配的字段將覆蓋前一個文件。新的值則添加到webapp
服務(wù)配置。
webapp: build: . environment: - DEBUG=1
使用-f和 - (破折號)作為文件名從stdin讀取配置。 當使用stdin時,配置中的所有路徑都與當前工作目錄相關(guān)。
-f標志是可選的。 如果您不在命令行中提供此標志,則Compose將遍歷工作目錄及其父目錄,以查找docker-compose.yml和docker-compose.override.yml文件。 您必須至少提供docker-compose.yml文件。 如果兩個文件都存在于相同的目錄級別,則Compose會將這兩個文件組合到一個配置中。
docker-compose.override.yml
除了docker-compose.yml
文件中的值之外,文件中的配置將被應(yīng)用。
您可以使用-f
標志來指定不在當前目錄中的Compose文件的路徑,無論是從命令行還是通過在shell或環(huán)境文件中設(shè)置COMPOSE_FILE環(huán)境變量。
有關(guān)在命令行中使用-f選項的示例,假設(shè)您正在運行Compose Rails示例,并在名為sandbox / rails的目錄中包含docker-compose.yml文件。 您可以使用像docker-compose pull這樣的命令,通過使用-f標志從任何地方獲取db服務(wù)的postgress映像,如下所示:docker-compose -f?/ sandbox / rails / docker-compose.yml pull db
以下是完整的示例:
$ docker-compose -f ~/sandbox/rails/docker-compose.yml pull db Pulling db (postgres:latest)...latest: Pulling from library/postgres ef0380f84d05: Pull complete 50cf91dc1db8: Pull complete d3add4cd115c: Pull complete 467830d8a616: Pull complete 089b9db7dc57: Pull complete 6fba0a36935c: Pull complete 81ef0e73c953: Pull complete 338a6c4894dc: Pull complete 15853f32f67c: Pull complete 044c83d92898: Pull complete 17301519f133: Pull complete dcca70822752: Pull complete cecf11b8ccf3: Pull complete Digest: sha256:1364924c753d5ff7e2260cd34dc4ba05ebd40ee8193391220be0f9901d4e1651 Status: Downloaded newer image for postgres:latest
-p
指定項目名稱每個配置都有一個項目名稱。如果你提供一個-p
標志,你可以指定一個項目名稱。如果您不指定標志,Compose將使用當前目錄名稱。另請參閱COMPOSE_PROJECT_NAME環(huán)境變量。
您可以為各種docker-compose
選項設(shè)置環(huán)境變量,包括-f
和-p
標志。
例如,COMPOSE_FILE環(huán)境變量與該-f
標志相關(guān),并且COMPOSE_PROJECT_NAME環(huán)境變量與該-p
標志相關(guān)。
另外,您可以在環(huán)境文件中設(shè)置其中一些變量。
CLI環(huán)境變量
在文件中聲明默認的環(huán)境變量