docker 提供的一個命令行工具,用來定義和運行由多個容器組成的應用php
一、安裝docker-compose (如下以centos7爲例)nginx
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-composegit
或者使用下方地址github
curl -L "https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compdocker
賦權json
chmod +x /usr/local/bin/docker-composecentos
查看版本緩存
docker-compose --versionbash
二、經常使用命令使用幫助app
[root@iZ4r8pe8pzf31gZ ~]# 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
--log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
--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
--project-directory PATH Specify an alternate working directory
(default: the path of the Compose file)
--compatibility If set, Compose will attempt to convert keys
in v3 files to their non-Swarm equivalent
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
3.經常使用命令
docker-compose up -d nginx 構建建啓動nignx容器
docker-compose exec nginx bash 登陸到nginx容器中
docker-compose down 刪除全部nginx容器,鏡像
docker-compose ps 顯示全部容器
docker-compose restart nginx 從新啓動nginx容器
docker-compose run --no-deps --rm php-fpm php -v 在php-fpm中不啓動關聯容器,並容器執行php -v 執行完成後刪除容器
docker-compose build nginx 構建鏡像 。
docker-compose build --no-cache nginx 不帶緩存的構建。
docker-compose logs nginx 查看nginx的日誌
docker-compose logs -f nginx 查看nginx的實時日誌
docker-compose config -q 驗證(docker-compose.yml)文件配置,當配置正確時,不輸出任何內容,當文件配置錯誤,輸出錯誤信息。
docker-compose events --json nginx 以json的形式輸出nginx的docker日誌
docker-compose pause nginx 暫停nignx容器
docker-compose unpause nginx 恢復ningx容器
docker-compose rm nginx 刪除容器(刪除前必須關閉容器)
docker-compose stop nginx 中止nignx容器
docker-compose start nginx 啓動nignx容器
四、其餘
源碼:https://github.com/docker/compose