编程知识 cdmana.com

docker compose部署

docker compose部署

————资源控制
[root@localhost ~]# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
4946cb00240c        bridge              bridge              local
7ad0dfddaa0f        host                host                local
906f0be0af7c        none                null                local

#自定义网络固定IP
docker network create --subnet=172.18.0.0/24 mynetwork
[root@localhost ~]# 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

[root@localhost ~]# docker run -itd --name test1 --net mynetwork --ip 172.18.0.100 centos:7 /bin/bash

[root@localhost ~]# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
4946cb00240c        bridge              bridge              local
7ad0dfddaa0f        host                host                local
b51371ede3af        mynetwork           bridge              local
906f0be0af7c        none                null                local
[root@localhost ~]# 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
[root@localhost ~]# docker exec -it 47132f608de0 /bin/bash
[root@47132f608de0 /]# yum install net-tools -y
[root@47132f608de0 /]# 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部署
#环境部署所有主机安装docker环境(内容为docker基础)
yum install docker-ce -y

#下载compose

[root@localhost ~]#  cp -p docker-compose /usr/local/bin/
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose 
[root@localhost ~]# mkdir compose_nginx
[root@localhost ~]# cd compose_nginx/
[root@localhost compose_nginx]# mkdir nginx
[root@localhost compose_nginx]# cd nginx/
[root@localhost nginx]# vim Dockfile
[root@localhost nginx]# vim run.sh
[root@localhost nginx]# rz -E
rz waiting to receive.
[root@localhost nginx]# ls
Dockerfile  nginx-1.12.0.tar.gz  run.sh
[root@localhost nginx]# cd ..
[root@localhost compose_nginx]# ls
nginx
[root@localhost 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: 
[root@localhost compose_nginx]# ls
docker-compose.yml  nginx
[root@localhost 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
[root@localhost compose_nginx]# tree ./
./
├── docker-compose.yml
├── nginx
   ├── Dockerfile
   ├── nginx-1.12.0.tar.gz
   └── run.sh
└── wwwroot
    └── index.html

[root@localhost 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

[root@localhost 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:

版权声明
本文为[osc_04b0bwu2]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4266664/blog/4712835

Scroll to Top