docker-compose deployment

First, the deployment compose
docker compose it easy to start quickly and efficiently manage our container, stop, restart and other operations, which is similar to a shell script under linux, based yaml grammar, in the document we can describe the architecture of the application, such as what mirroring, data volumes information network mode, listening ports. We can define a multi-use container (such as jumpserver) compose in a file, and then start the application through which compose.
 
 
1: Install compose
[root@host1 ~]# curl -L https://github.com/docker/compose/releases/download/1.17.0-rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
 
2: give permission
[root@host1 ~]# chmod 755 !$
 
3: check whether the installation is successful
[root@host1 ~]# docker-compose -v
docker-compose version 1.17.0-rc1, build a0f95af
 
Two, compose usage
 
Syntax: docker-compose Parameters Syntax
示例:docker-compose -f docker-compos.yml logs
 
 
1: Query Version Information
Description: Compose distinguish Version 1 and Version 2 (Compose 1.6.0 +, Docker Engine 1.10.0+). Version 2 supports more instructions. Version 1 does not declare a default version is "version 1". Version 1 will be abandoned in the future.
[root@host1 ~]# docker-compose version
docker-compose version 1.17.0-rc1, build a0f95af
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
 
2:编写compose执行文件,后缀为yml
说明:image是指定docker镜像、prots指定本地和容器映射的端口、networks指定容器调用网卡模式、volumes指定本地目录和容器的文件存放映射目录
[root@host1 ~]# vim docker-compose.yml
version: "2"
services:
nginx:
image: nginx
ports:
- "81:80"
networks:
- "net1"
volumes:
- /data/:/data
tomcat:
image: tomcat
ports:
- "8081:8080"
networks:
- "net2"
volumes:
- /data/:/data1
entrypoint: tail -f /etc/passwd
networks:
net1:
driver: bridge
net2:
driver: bridge
 
3:执行docker-compose文件
说明:compose启动关闭命令方式有:start、stop,up、down;-f指定compose执行文件的路径,-d放置在后台启动
[root@host1 ~]# docker-compose up -d
Creating network "root_net2" with driver "bridge"
Creating network "root_net1" with driver "bridge"
Creating root_nginx_1 ...
Creating root_tomcat_1 ...
Creating root_nginx_1
Creating root_tomcat_1 ... done
 
4:加ps查看启动的任务,相当于docker ps命令,但是比docker ps信息输出比较直观
[root@host1 ~]# docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------
root_nginx_1 /bin/sh -c /usr/local/ngin ... Up 0.0.0.0:80->80/tcp
root_tomcat_1 tail -f /etc/passwd Up 0.0.0.0:8080->8080/tcp

Guess you like

Origin www.cnblogs.com/douyi/p/11573784.html