I have created three networks A, B and C using docker on a ubuntu VM, each network contained the three containers 2 busybox and 1 nginx. Each nginx container in different network i have port-forwarded on 80
81
and 82
respectively using below commands:
sudo docker run -itd --rm -p 82:82 --network C --name web3 nginx
sudo docker run -itd --rm -p 81:81 --network B --name web2 nginx
sudo docker run -itd --rm -p 80:80 --network A --name web1 nginx
but when i tried to access the container from my host machine providing the ip address of my vm along with port e.g. https://192.168.18.240:82
it does not give access to that container in different network. While giving the only IP address with port 80 am able to access the nginx but not on port 82
and 81
. I have cleared the cache and clear the browsing history but all in vain.
CodePudding user response:
All of the docker nginx containers listen on port 80. You are mapping B and C to the wrong container port.
sudo docker run -itd --rm -p 82:**80** --network C --name web3 nginx
sudo docker run -itd --rm -p 81:**80** --network B --name web2 nginx
sudo docker run -itd --rm -p 80:80 --network A --name web1 nginx