Docker三剑客之Compose
Posted walkinginthesun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker三剑客之Compose相关的知识,希望对你有一定的参考价值。
参考:
1. 下载安装
curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
cd /usr/local/bin/
chmod +x docker-compose
2. 启动
mkdir compose
cd compose/
vim docker-compose.yml
docker-compose up
docker-compose.yml
version: ‘3‘
services:
redis:
image: "redis:latest"
3. docker-compose help
[[email protected] 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
[[email protected] compose]#
4. 启动项目中的服务(容器)
[[email protected] compose]# docker-compose start redis
Starting redis ... done
[[email protected] compose]# docker-compose ps
Name Command State Ports
-------------------------------------------------------------------
compose_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp
[[email protected] compose]#
5. docker-compose exec
[[email protected] compose]# docker-compose exec redis bash
[email protected]:/data# redis-cli
127.0.0.1:6379> keys *
1) "name"
127.0.0.1:6379>
127.0.0.1:6379>
以上是关于Docker三剑客之Compose的主要内容,如果未能解决你的问题,请参考以下文章
Linux企业运维——Docker三剑客之docker-compose