赞
踩
一、介绍
源码:https://github.com/docker/compose
官方文档:https://docs.docker.com/glossary/?term=amd64
安装:https://docs.docker.com/compose/install/
二、常用命令
· build(构建yml中某个服务的镜像)
如上,web这个服务是依赖于镜像build的。在本地 也存在Dockerfile文件。
可以使用docker-compose build来构建服务的镜像。
· ps(查看已经启动的服务状态)
· kill(停止某个服务)
· logs(可以查看某个服务的log)
· port(打印绑定的public port)
· pull(pull服务镜像)
· up(启动yml定义的所有服务)
· stop(停止yml中定义的所有服务)
· start(启动被停止的yml中的所有服务)
· kill(强行停止yml中定义的所有服务)
· rm(删除yml中定义的所有服务)
· restart(重启yml中定义的所有服务)
· scale(扩展某个服务的个数,可以向上或向下)
· migrate-to-labels(这个没有实际尝试。根据介绍是将服务从1.2迁移到1.3带labels的版本。docker之前不支持label)
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
-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)
Commands:
build Build or rebuild services
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
help Get help on a command
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pulls 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
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
Usage: build [options] [SERVICE...]
Options:
Usage: config [options]
为服务创建容器.只是单纯的create,还需要使用start启动compose
Usage: create [options] [SERVICE...]
--build 创建容器前,生成镜像.
Usage: down [options]
attached to containers.
--remove-orphans Remove containers for services not defined in the
Usage: exec [options] SERVICE COMMAND [ARGS...]
Options:
-d 分离模式,后台运行命令.
--privileged 获取特权.
--user USER 指定运行的用户.
-T 禁用分配TTY. By default `docker-compose exec`
docker-compose exec web sh
Usage: unpause [SERVICE...]
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]
Usage: pull [options] [SERVICE...]
Usage: rm [options] [SERVICE...]
Options:
-a, --all Also remove one-off containers created by
By default, anonymous volumes attached to containers will not be removed. You can override this with -v
. To list all volumes, use docker volume ls
.
Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
-T 禁用TTY.
启动web服务器,并执行bash命令.
$ docker-compose run web bash
$ docker-compose run --service-ports web python manage.py shell
$ docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
$ docker-compose run db psql -h db -U docker
不linke容器,单独启动指定容器:
$ docker-compose run --no-deps web python manage.py shell
Usage: up [options] [SERVICE...]
Options:
-d 后台运行,输出容器的名字.
Incompatible with --abort-on-container-exit.
--no-deps 不启动link服务.
Incompatible with --no-recreate.
Incompatible with --force-recreate.
--abort-on-container-exit 任何容器停止,自动停止所有容器.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。