bridge網路實現多個單主機進行通訊
2、
#建立橋接網路卡
[root@Docker1 ~]# docker network create --driver bridge --subnet 172.100.100.0/24 --gateway 172.100.100.254 my_net
87b5edc787de5b2bb3a6b965ebe24cbf74508dda0b717e956c797bfee12c100d
#建立bbox2、bbox3容器
[root@Docker1 ~]# docker run -itd --name bbox2 --network my_net busybox
a5a44577d384686cf54e79f6fd859f24eaf95703c57e9f14542bf0b8ecd60ebc
[root@Docker1 ~]# docker run -itd --name bbox3 --network my_net busybox
08ba77e89f517b1df468080b16a4ae13b052768c27bb9fceb3937f615135446d
#驗證兩個是否能通訊
#使用bbox2容器檢視是否能與bbox3通訊
[root@Docker1 ~]# docker exec -it bbox2 sh
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
7: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:64:64:01 brd ff:ff:ff:ff:ff:ff
inet 172.100.100.1/24 brd 172.100.100.255 scope global eth0
valid_lft forever preferred_lft forever
/ # ping 172.100.100.2
PING 172.100.100.2 (172.100.100.2): 56 data bytes
64 bytes from 172.100.100.2: seq=0 ttl=64 time=0.120 ms
64 bytes from 172.100.100.2: seq=1 ttl=64 time=0.062 ms
64 bytes from 172.100.100.2: seq=2 ttl=64 time=0.081 ms
--- 172.100.100.2 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.062/0.087/0.120 ms
/ # exit
#使用bbox3容器檢視是否能與bbox2通訊
[root@Docker1 ~]# docker exec -it bbox3 sh
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
9: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:64:64:02 brd ff:ff:ff:ff:ff:ff
inet 172.100.100.2/24 brd 172.100.100.255 scope global eth0
valid_lft forever preferred_lft forever
/ # ping 172.100.100.1
PING 172.100.100.1 (172.100.100.1): 56 data bytes
64 bytes from 172.100.100.1: seq=0 ttl=64 time=0.056 ms
64 bytes from 172.100.100.1: seq=1 ttl=64 time=0.062 ms
64 bytes from 172.100.100.1: seq=2 ttl=64 time=0.063 ms
--- 172.100.100.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.056/0.060/0.063 ms
3、
#建立nginx映象
[root@Docker1 ~]# vim Dockerfile
FROM centos:7
ADD nginx-1.11.5.tar.gz /usr/src/
RUN yum -y install net-tools zlib zlib-devel openssl-devel openssl pcre gcc* vim /sbin/ip
RUN useradd nginx
WORKDIR /usr/src/nginx-1.11.5/
RUN ./configure && gmake && gmake install
RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module && make && make install
RUN ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
RUN echo "#/bin/bash" >/nginx.sh
RUN echo "nginx" >> ./nginx.sh
RUN sh ./nginx.sh
EXPOSE 80
[root@Docker1 ~]# docker build -t nginx .
#將nginx新增到連個橋接網路卡中
[root@Docker1 ~]# docker network create --driver bridge myapp_net
8da4e20877abdd6a2c68ecd5ab5bfa834721622243f1e99057b9b437a54aecdb
[root@Docker1 ~]# docker run -itd --name nginx nginx
364c4e3b5aab7d3f6a80381930a62408b5932699a7a0c49f6a31fcc3979d43f6
[root@Docker1 ~]# docker network connect my_net nginx
[root@Docker1 ~]# docker network connect myapp_net nginx
#建立bbox1容器
[root@Docker1 ~]# docker run -itd --name bbox1 --network container:nginx busybox
d59bf9efd25552446727b3faf0e3a09941a953b3b0afd996c4f745beb80003e1
#檢視nginx容器中的網路卡是否與bbox1中的網路卡是否相同
[root@Docker1 ~]# docker exec -it nginx sh
sh-4.2# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
28: eth0@if29: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
30: eth1@if31: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:64:64:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.100.100.3/24 brd 172.100.100.255 scope global eth1
valid_lft forever preferred_lft forever
32: eth2@if33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.18.0.2/16 brd 172.18.255.255 scope global eth2
valid_lft forever preferred_lft forever
sh-4.2# exit
exit
[root@Docker1 ~]# docker exec -it bbox1 sh
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
28: eth0@if29: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
30: eth1@if31: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:64:64:03 brd ff:ff:ff:ff:ff:ff
inet 172.100.100.3/24 brd 172.100.100.255 scope global eth1
valid_lft forever preferred_lft forever
32: eth2@if33: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.2/16 brd 172.18.255.255 scope global eth2
valid_lft forever preferred_lft forever
4、
#建立php映象
[root@Docker1 ~]# vim Dockerfile
FROM centos:7
ADD php-5.5.38.tar.gz /usr/src
WORKDIR /usr/src/php-5.5.38
RUN yum -y install gd libxml2-devel libjpeg-devel libpng-devel gcc make vim /sbin/ip
RUN ./configure --prefix=/usr/local/php --with-gd --with-zlib \
--with-config-file-path=/usr/loca/php \
--enable-fpm --enable-mbstring --with-jpeg-dir=/usr/lib && make && make install
WORKDIR /
RUN cp /usr/src/php-5.5.38/php.ini-development /usr/local/php/php.ini
RUN sed -i '/default_charset/c \default_charset = "utf-8"' /usr/local/php/php.ini
RUN sed -i '/short_open_tag/c \short_open_tag = On' /usr/local/php/php.ini
RUN cp /usr/src/php-5.5.38/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
RUN chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm
RUN cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
RUN sed -i '/;pid = run/c \pid = run/php-fpm.pid' /usr/local/php/etc/php-fpm.conf && \
sed -i '/user =/c \user = nginx' /usr/local/php/etc/php-fpm.conf && \
sed -i '/group =/c \group = nginx' /usr/local/php/etc/php-fpm.conf && \
sed -i '/pm.max_children/c \pm.max_children = 50' /usr/local/php/etc/php-fpm.conf && \
sed -i '/pm.start_servers/c \pm.start_servers = 20' /usr/local/php/etc/php-fpm.conf && \
sed -i '/pm.min_spare_servers/c \pm.min_spare_servers = 5' /usr/local/php/etc/php-fpm.conf && \
sed -i '/pm.max_spare_servers/c \pm.max_spare_servers = 35' /usr/local/php/etc/php-fpm.conf
RUN useradd nginx
RUN mkdir /www
RUN echo '<?' >/www/index.php
RUN echo 'phpinfo();' >>/www/index.php
RUN echo '?>' >>/www/index.php
[root@Docker1 ~]# docker build -t php .
#整合nginx和php
#php容器
[root@Docker1 ~]# docker run -itd --name php --network myapp_net php
e748a4c409fb4328bdea47b3bdc72314f2d7947179559b1318d074b1a7589b66
[root@Docker1 ~]# docker exec -it php /bin/sh
sh-4.2# vim /usr/local/php/etc/php-fpm.conf
164 listen = 172.18.0.2:9000 #本機IP
#nginx容器
sh-4.2# vim /usr/local/nginx/conf/nginx.conf
45 index index.php index.html index.htm;
65 location ~ \.php$ {
66 root /www/; #index.php存在的目錄(在php端)
67 fastcgi_pass 172.18.0.2:9000; #php的IP
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf;
71 }
sh-4.2# nginx -s reload
#驗證
sh-4.2# elinks 172.18.0.3/index.php #本機IP
相關文章
- docker的網路-單主機(三種原生網路)none、host、bridgeDockerNone
- 簡單的Java實現Netty進行通訊JavaNetty
- 網路通訊2:TCP通訊實現TCP
- USB共享網路:android手機通過USB與Ubuntu進行socket網路通訊AndroidUbuntu
- 使用UDP如何進行網路通訊UDP
- java多執行緒實現TCP網路Socket程式設計(C/S通訊)Java執行緒TCP程式設計
- 網路通訊4:HTTP實現二進位制傳輸HTTP
- python實現兩臺不同主機之間進行通訊(客戶端和服務端)——SocketPython客戶端服務端
- 網路通訊2:TCP簡單通訊TCP
- 單一docker主機網路Docker
- 一個簡單混合協議通訊列子,物聯網和網際網路通訊。協議
- 單執行緒的JS如何實現多個互動同時進行執行緒JS
- Mininet主機與真實網路互通方案實現
- 網路通訊3:HTTP實現文字傳輸HTTP
- 網路通訊單元NU系列
- docker容器網路bridgeDocker
- 從零開始實現簡單 RPC 框架 6:網路通訊之 NettyRPC框架Netty
- 從零開始實現簡單 RPC 框架 9:網路通訊之心跳與重連機制RPC框架
- sharedWorker 實現多頁面通訊
- [iptables] 基於iptables實現的跨網路通訊
- 用VC在區域網實現IP多播通訊
- Windows 中的命名管道(Named Pipes)是一種在程序間進行通訊的機制。它允許兩個或多個程序之間透過檔案系統的一個特殊路徑進行通訊,從而實現資料的傳輸和共享。Windows
- 同網段不同網段主機間通訊原理
- 安卓okhttp3進行網路請求,一個簡單的登入頁面的實現安卓HTTP
- WebRTC---網路實時通訊Web
- 多執行緒通訊軟體——登入介面的實現執行緒
- 從零開始實現簡單 RPC 框架 5:網路通訊之序列化RPC框架
- 網路通訊
- Kubernetes的容器網路通訊機制
- 一文搞懂如何使用Node.js進行TCP網路通訊Node.jsTCP
- 從零開始實現簡單 RPC 框架 8:網路通訊之 Request-Response 模型RPC框架模型
- 052、overlay如何實現跨主機通訊?(2019-03-19 週二)
- 乾元通多鏈路通訊裝置保障高鐵網路穩定
- 利用光貓多餘網口聯通家裡網路(省個交換機)
- 實現多個標籤頁之間通訊的幾種方法
- 通過進攻心態進行有效的網路防禦
- 一個簡單API,一鍵實現多通道訊息推送API
- Java進階:基於TCP通訊的網路實時聊天室JavaTCP