docker compose部署
————资源控制
[[email protected] ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
4946cb00240c bridge bridge local
7ad0dfddaa0f host host local
906f0be0af7c none null local
docker network create --subnet=172.18.0.0/24 mynetwork
[[email protected] ~]# ifconfig
br-b51371ede3af: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.255.0 broadcast 172.18.0.255
ether 02:42:d7:6a:3d:f3 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] ~]# docker run -itd --name test1 --net mynetwork --ip 172.18.0.100 centos:7 /bin/bash
[[email protected] ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
4946cb00240c bridge bridge local
7ad0dfddaa0f host host local
b51371ede3af mynetwork bridge local
906f0be0af7c none null local
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47132f608de0 centos:7 "/bin/bash" About a minute ago Up About a minute test1
[[email protected] ~]# docker exec -it 47132f608de0 /bin/bash
[[email protected] /]# yum install net-tools -y
[[email protected] /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.100 netmask 255.255.255.0 broadcast 172.18.0.255
ether 02:42:ac:12:00:64 txqueuelen 0 (Ethernet)
RX packets 6968 bytes 12136790 (11.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4113 bytes 225662 (220.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
——————compose部署
yum install docker-ce -y
[[email protected] ~]# cp -p docker-compose /usr/local/bin/
[[email protected] ~]# chmod +x /usr/local/bin/docker-compose
[[email protected] ~]# mkdir compose_nginx
[[email protected] ~]# cd compose_nginx/
[[email protected] compose_nginx]# mkdir nginx
[[email protected] compose_nginx]# cd nginx/
[[email protected] nginx]# vim Dockfile
[[email protected] nginx]# vim run.sh
[[email protected] nginx]# rz -E
rz waiting to receive.
[[email protected] nginx]# ls
Dockerfile nginx-1.12.0.tar.gz run.sh
[[email protected] nginx]# cd ..
[[email protected] compose_nginx]# ls
nginx
[[email protected] compose_nginx]# vim docker-compose.yml
version: '3'
services:
nginx:
hostname: nginx
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- 1216:80
- 1217:443
networks:
- yun
volumes:
- ./wwwroot:/usr/local/nginx/html
networks:
yun:
[[email protected] compose_nginx]# ls
docker-compose.yml nginx
[[email protected] compose_nginx]# docker-compose -f docker-compose.yml up -d
ls
cd wwwroot
vim index.html
<h1>this is kevin web</h1>
yum install tree -y
[[email protected] compose_nginx]# tree ./
./
├── docker-compose.yml
├── nginx
│ ├── Dockerfile
│ ├── nginx-1.12.0.tar.gz
│ └── run.sh
└── wwwroot
└── index.html
[[email protected] compose_nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5a6c6da883d compose_nginx_nginx "/run.sh" 3 minutes ago Up 3 minutes 0.0.0.0:1216->80/tcp, 0.0.0.0:1217->443/tcp compose_nginx_nginx_1
47132f608de0 centos:7 "/bin/bash" 43 minutes ago Up 43 minutes test1
[[email protected] compose_nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
compose_nginx_nginx latest 502db66e6ec9 3 minutes ago 516MB
centos 7 7e6257c9f8d8 6 weeks ago 203MB
iptables -F
setenforce 0
————————tomcat
version: '3'
services:
nginx:
hostname: nginx
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- 1216:80
- 1217:443
networks:
- yun
volumes:
- ./wwwroot:/usr/local/nginx/html
tomcat:
hostname: tomcat
build:
context: ./tomcat
dockerfile: Dockerfile
ports:
- 1234:8080
networks:
- hu
networks:
yun:
hu: