docker-compose Introduction and Installation

I. Introduction

Compose tools for defining and running multiple applications Docker containers, docker service orchestration tool is mainly applied to complex applications built on the Docker, Compose managed by a plurality of containers docker profile suitable combination of a plurality of containers a scene development.

Use compose, you can use yaml file to configure service applications.

Then, by a command, you can create and start all services from the configuration.

Official website: https: //docs.docker.com/compose/overview/

Second, the use

compose for all environments: production, development, testing and CI workflow.

Use compose basically a three-step process:

1. dockerfile, or custom application environments mirror to replicate anywhere.

2. The definition of applications in service composition docker-compose.yml so that they can run together in a separate environment.

3. Run docker compose up up and running the entire application.

Third, the installation docker-ce

First, install docker

1, the installation dependent on the environment

[root@jenkins ~]# yum -y install yum-utils device-mapper-persistent-data  lvm2

2. Preparation mirror source

[root@jenkins ~]# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo

3, mounting docker-ce

[root@jenkins ~]# yum -y install docker-ce

4. Start docker

[root@docker ~]# systemctl start docker
[root@docker ~]# systemctl enable docker
[root@docker ~]# docker version                     #查看docker版本
5, Ali cloud images accelerator
https://account.aliyun.com # Ali cloud Site

Docker for the user of the client version greater than 1.10.0

You can modify the daemon configuration file /etc/docker/daemon.json to use accelerator

[Docker the root @ ~] CAT # << the EOF> /etc/docker/daemon.json
{
  "Registry-Mirrors": [ "HTTPS: // you aliyun mirror accelerator .com"]
}
the EOF
[root @ docker ~] # systemctl daemon-reload # reload the configuration 
[root @ docker ~] # systemctl restart docker # restart the service
 
Fourth, the installation docker-compose
[root@docker ~]# yum -y install libcurl libcurl-devel
[root@docker ~]# curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-'uname -s'-'uname -m' -o /usr/local/bin/docker-compose
[root@docker ~]# ls
anaconda-ks.cfg         docker-compose 
[root@docker ~]# mv docker-compose /usr/local/bin/
[root@docker ~]# chmod +x /usr/local/bin/docker-compose
[root@docker ~]# docker-compose --version
docker-compose version 1.21.1, build 5a3f1a3
 
五、docker-compose用法
常用选项:
--verbose:输出更多的调试信息
--version:查看compose的版本
-f --file FILE:使用特定的compose模板文件,默认为docker-compose.yml。
-p --project-name NAME 指定项目名称,默认使用目录名称。
常用命令:
build:构建或重建服务
ps:查看已经启动的服务状态       
kill:停止某个服务、杀掉容器       
logs:可以查看某个服务的log、显示容器的输出内容       
port:打印绑定的public port(开放端口)        
pull:拉取服务镜像      
up:启动yml定义的所有服务     
stop:停止yml中定义的所有服务       
start:启动被停止的yml中的所有服务        
kill:强行停止yml中定义的所有服务        
rm:删除yml中定义的所有服务      
restart:重启yml中定义的所有服务        
scale:设置服务的容器数目
run:运行一个一次性命令
 
 

Guess you like

Origin www.cnblogs.com/ZCQ123456/p/11921817.html