docker 问题处理汇总
1.解决docker 端口防火墙拦截不住问题处理:
vim /etc/docker/daemon.json
{
"iptables": false
}
2.解决容器不能访问外网和内网同网段ip
开启ipv4端口转发
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p
开启转发
firewall-cmd --add-masquerade --permanent
重新加载运行
firewall-cmd --reload
执行后,容器内部可以访问外网
3.解决docker nginx 获取不到真实ip
在 docker-compare.xml services:下配置network_mode: "host"
version: '3'
services:
nginx:
image: nginx
container_name: nginx_test
restart: always
ports:
- 80:80
volumes:
- /data/nginx/www:/usr/share/nginx/html
- /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- /data/nginx/logs:/var/log/nginx
network_mode: "host"
重启docker
systemctl restart docker
重新打包容器
docker-compose -f docker-compose.yml up -d