解决方法
创建一个
docker network create --subnet=192.11.0.0/24 my-br0
加入到
docker network disconnect bridge mariadb
docker network connect my-br0 --ip=192.11.0.14 mariadb
docker network disconnect bridge my_php73-fpm
docker network connect my-br0 --ip=192.11.0.15 my_php73-fpm
docker network disconnect bridge my_nginxphp_73
docker network connect my-br0 --ip=192.11.0.16 my_nginxphp_73
docker network disconnect my-br0 my_nginxphp_73
修改nginx的配置文件 把
vim /a/nginx/conf/conf.d/runoob-test-php.conf
php-fpm的ip改成我们手动配置的固定ip地址
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass 192.11.0.15:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
如果是新的用下面的加入到容器桥接网卡
docker run --name my_nginxphp_73 -p 8093:80 -d \
-v /a/nginx/www:/usr/share/nginx/html:ro \
-v /a/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
--net my-br0 --ip 192.11.0.16 \
--link my_php73-fpm:php \
nginx
跟随系统启动
docker update --restart=always my_nginxphp_73
查看网卡地址手动分配是否正常
docker network inspect my-br0
显示如下
"Containers": {
"600b53135aec51a6813a32ca50c60722ee6a95f7c2fcc5f0e51cdf9ee69ccde0": {
"Name": "mariadb",
"EndpointID": "facd2ad23b8c00e944a125147ddc6a522e3213d91dc5c9719fafb208e930b64e",
"MacAddress": "02:42:c0:0b:00:0e",
"IPv4Address": "192.11.0.14/24",
"IPv6Address": ""
},
"edde7fee6c7b48acef01d02f2eb91521ece85078d2f01fef190c55b5771c76cd": {
"Name": "my_nginxphp_73",
"EndpointID": "f06653df6ba35dd1159850b1630e029aa0ff2d8fec43f8345aa028f0e6d46014",
"MacAddress": "02:42:c0:0b:00:10",
"IPv4Address": "192.11.0.16/24",
"IPv6Address": ""
},
"fdd5fc8de0805c11286ffb95a43f736ef9ac393d8bcb558b056213e020093e25": {
"Name": "my_php73-fpm",
"EndpointID": "1794e63bb2d4d30e6951f12761689da370feafd2f0cdf0f01cbf5374b9d3e0a5",
"MacAddress": "02:42:c0:0b:00:0f",
"IPv4Address": "192.11.0.15/24",
"IPv6Address": ""
}
},
正常手动分配地址后
把phpmyadmin 的mariadb 容器地址更改就可以了
下面是参考资料
固定容器的ip地址
(9条消息)Docker 配置容器固定IP - liufuwu1的博客 - CSDN博客 https://blog.csdn.net/liufuwu1/article/details/88096213
docker network create --subnet=172.172.0.0/24 docker-br0
docker network rm docker-br0 移除网桥。
docker run -i -d --net docker-br0 --ip 172.172.0.10 --name nginx -v /usr/local/software/:/mnt/software/ 3bee3060bfc8 /bin/bash
第六步:配置路由表
#添加路由规则
ip route add 对方容器所在的ip网段/子网掩码 via 对方虚拟机ip dev 通过哪个网卡通信
如: ip route add 172.172.1.0/24 via 192.168.1.106 dev eno16777736
添加完成之后,可以使用 route命令 查看添加之后的规则,也可以使用 ip route del 172.172.1.0/24 移除路由规则
在192.168.1.105 和 192.168.1.106虚拟机上,分别添加对应的路由规则!
192.168.1.105: ip route add 172.172.1.0/24 via 192.168.1.106 dev eno16777736
192.168.1.106: ip route add 172.172.0.0/24 via 192.168.1.105 dev eno16777736
(9条消息)docker network 基本命令 - liu11yutao的专栏 - CSDN博客 https://blog.csdn.net/liu11yutao/article/details/85006430
这个文章可以了解容器网络