I have started three docker containers with a port mapping long time ago, I cannot access the Docker-mapped ports from other machines recently, will I can visit port from the machine witch run the docker container.
After my check, I can confirm that the issue lies with Docker. I have attempted to restart the Docker service and the container, but to no avail. -- For some reason, I can't remove this container.
Answers
If you're experiencing issues with accessing Docker-mapped ports from other machines, but you can access them from the machine running the Docker containers, it's possible that there could be several reasons for this problem. Here are some steps you can take to troubleshoot and resolve the issue:
-
Check Docker Container Status: First, check the status of your Docker container to ensure that it's running:
docker ps
If your container is not running, start it using:
docker start <container_name_or_id>
-
Verify Port Mapping: Confirm that the ports are correctly mapped from the host machine to the Docker container. You can check this by inspecting the container:
docker inspect <container_name_or_id>
Look for the
Ports
section in the output to ensure that the ports are mapped correctly. -
Check Firewall Settings: Ensure that the firewall on the host machine is not blocking incoming connections to the Docker-mapped ports. You may need to configure firewall rules to allow traffic on these ports.
-
Check Docker Network Configuration: Verify the Docker network configuration to ensure that it's allowing external connections to reach the containers. By default, Docker containers are attached to the bridge network, which should allow external access.
-
Restart Docker Service: Sometimes, restarting the Docker service can resolve networking issues. Restart the Docker service using:
sudo systemctl restart docker
-
Check Container Logs: Review the logs of your Docker container for any errors or issues that might be preventing external access. You can view container logs using:
docker logs <container_name_or_id>
-
Inspect Container Configuration: If you suspect that the container configuration might be causing the issue, you can inspect its configuration using:
docker inspect <container_name_or_id>
Look for any specific configurations that might affect network connectivity.
-
Verify Host Network Configuration: Ensure that the host machine's network configuration allows incoming connections on the mapped ports. Check for any network-level restrictions or configurations that might be interfering with external access to Docker containers.
-
Remove and Recreate Container: If all else fails, you can try removing the existing container and recreating it with the same port mappings. Be cautious as this will delete any data stored within the container:
docker stop <container_name_or_id> docker rm <container_name_or_id>
Then recreate the container with the same port mappings as before.
By following these steps, you should be able to identify and resolve the issues preventing external access to Docker-mapped ports from other machines. If you continue to experience problems, consider consulting Docker's documentation or seeking assistance from Docker community forums for further troubleshooting.