I am experiencing an intermittent issue with accessing my Docker containers from external networks. After restarting the Docker service, the containers become accessible from outside the network, but after some time, they can no longer be reached externally. However, throughout this period, all containers remain accessible from the host machine. I would appreciate your assistance in resolving this matter.
Issue Description
- Docker containers initially become accessible externally after restarting the Docker service
- After an unspecified duration, external access to these containers is lost, although they remain accessible from the host machine (verified using curl -X GET http://{{machine-ip-addr}}:80)
- Confirmed via tcpdump that network interface eth0 is receiving traffic on ports 80 and 443.
- UFW is disabled, ruling it out as the cause of the issue.
- No recent changes in Docker configuration or network settings correspond with the issue onset.
- Verified Docker container configuration; necessary ports are exposed.
- The docker-compose file is structured like this simplified version:
version: '3.3'
services:
l-app:
restart: always
image: s-h-l/l-app:1.0.0
volumes:
- shared-volume:/tmp
ports:
- 80:8080
volumes:
shared-volume:
Checked iptables rules; found no rules blocking the relevant ports
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (2 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.18.0.2 tcp dpt:http-alt
ACCEPT tcp -- anywhere 172.18.0.3 tcp dpt:http
ACCEPT tcp -- anywhere 172.18.0.5 tcp dpt:postgresql
ACCEPT tcp -- anywhere 172.18.0.4 tcp dpt:http-alt
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target prot opt source destination
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Environment Details
- Host Operating System: 5.4.0-167-generic #184-Ubuntu 20.04 LTS
- Docker Version: 24.0.7
- Docker-Compose Version: 1.25.0
The intermittent nature of the issue, particularly its correlation with restarting the Docker service, suggests a potential problem with network routing or external firewall settings beyond the host machine. Your insights or guidance on this matter would be greatly appreciated. Thank you for your assistance.