CentOS에서 container를 사용하는데 외부와 통신하지 못 하는 경우를 확인했습니다. 가령 nginx를 설치하고 proxy-pass를 다른 호스트 또는 외부로 설정했을 때 호스트를 찾지 못 한다거나 접속할 수 없는 경우가 발생했습니다. target-host의 방화벽 문제일 수 도 있지만, source 호스트의 iptables에서 docker0-interface의 외부 통신을 허용하지 않아서 일수도 있습니다. outbound를 아래처럼 열어줍니다.
# Check what interface docker is using, e.g. ‘docker0’ip link show# Check available firewalld zones, e.g. ‘public’sudo firewall-cmd –get-active-zones# Check what zone the docker interface it bound to, most likely ‘no zone’ yetsudo firewall-cmd –get-zone-of-interface=docker0# So add the ‘docker0’ interface to the ‘public’ zone. Changes will be visible only after firewalld reloadsudo nmcli connection modify docker0 connection.zone public
# 또는 아래 명령을 사용할 수 있다.(테스트 안된 코드)
#sudo firewall-cmd –permanent –zone=internal –add-interface=ens34′# Masquerading allows for docker ingress and egress (this is the juicy bit)sudo firewall-cmd –zone=public –add-masquerade –permanent# Optional open required incomming ports (wasn’t required in my tests)# sudo firewall-cmd –zone=public –add-port=443/tcp# Reload firewalldsudo firewall-cmd –reload# Reload dockerdsudo systemctl restart docker
추가로 컨테이너 내부로 접근하지 못 할경우
[상태확인]
sudo sysctl net.ipv4.ip_forward
[설정]
sudo sysctl -w net.ipv4.ip_forward=1