Score:0

Docker accessible via localhost:8080 & 127.0.0.1:8080 but not via IP

cn flag

I have the below scenario - 3x Vagrant VMs are spinned from the below Vagrantfile, up and running (visible within Oracle VirtualBox).

I am logged on docker1, the network type is "NAT", portforwarding is used (Guest:8080, Host:8080).

I am able to access the page from localhost:8080 & 127.0.0.1:8080 & 127.0.1.1:8080. However, I have no access via the IP (192.168.99.101:8080 is "Taking too long to respond" and can't be reached).

Vagrant.configure("2") do |config|

    config.vm.define "docker1" do |docker1|
        docker1.vm.box="xxx/centos-stream-8"
        docker1.vm.hostname = "docker1.do1.lab"
        docker1.vm.network "private_network", ip: "192.168.99.101"
        docker1.vm.provision "shell", path: "docker-setup.sh"
        docker1.vm.provision "shell", path: "other-steps.sh"
        docker1.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--memory", "1536"]
        end
    end
    
    config.vm.define "docker2" do |docker2|
        docker2.vm.box="xxx/centos-stream-8"
        docker2.vm.hostname = "docker2.do1.lab"
        docker2.vm.network "private_network", ip: "192.168.99.102"
        docker2.vm.provision "shell", path: "docker-setup.sh"
        docker2.vm.provision "shell", path: "other-steps.sh"
        docker2.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--memory", "1536"]
        end
    end
    
    config.vm.define "docker3" do |docker3|
        docker3.vm.box="xxx/centos-stream-8"
        docker3.vm.hostname = "docker3.do1.lab"
        docker3.vm.network "private_network", ip: "192.168.99.103"
        docker3.vm.provision "shell", path: "docker-setup.sh"
        docker3.vm.provision "shell", path: "other-steps.sh"
        docker3.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--memory", "1536"]
        end
    end
end

the docker-setup.sh file is below:

#!/bin/bash

echo "* Add Docker repository ..."
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

echo "* Install Docker ..."
dnf install -y docker-ce docker-ce-cli containerd.io

echo "* Enable and start Docker ..."
systemctl enable docker
systemctl start docker

echo "* Add vagrant user to docker group ..."
usermod -aG docker vagrant

the other-steps.sh file is below:

#!/bin/bash

echo "* Add hosts ..."
echo "192.168.99.101 docker1.do1.lab docker1" >> /etc/hosts
echo "192.168.99.102 docker2.do1.lab docker2" >> /etc/hosts
echo "192.168.99.103 docker3.do1.lab docker3" >> /etc/hosts

echo "* Install Additional Packages ..."
dnf install -y jq tree git nano

echo "* Firewall - swarm - open ports ..."
firewall-cmd --add-port=2377/tcp --permanent
firewall-cmd --add-port=4789/udp --permanent
firewall-cmd --add-port=7946/tcp --permanent
firewall-cmd --add-port=7946/udp --permanent

echo "* Firewall - app - open port 8080 ..."
firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload

The networks are below:

[vagrant@docker1 etc]$ docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
f2351cd29061   bridge            bridge    local
f91a21d83931   docker_gwbridge   bridge    local
c5fc9aedf330   host              host      local
oc2i4c2czira   ingress           overlay   swarm
50fe2b72573c   none              null      local

The etc/hosts content is here:

[vagrant@docker1 etc]$ cat hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.1.1 docker1.do1.lab docker1
192.168.99.101 docker1.do1.lab docker1
192.168.99.102 docker2.do1.lab docker2
192.168.99.103 docker3.do1.lab docker3

The command used to spin up a container is the below one:

docker container run -d --name web -p 8080:80 -e APP_MODE='test' swarm-app

I've researched tons of articles with the same issue but still cannot find a solution. I suppose this might have something to do with the DNS resolution of the IP address in question?

Update: I am opening in CMD via curl the below addresses (Port Forwarding Host:8080, Guest:80), if there is any info to provide, please let me know: `[vagrant@docker1 ~]$ curl http:/localhost:8080 -> does not open in browser

Hello Docker Swarm!

Running in test mode.

Served by: be93b0268b1d

[vagrant@docker1 ~]$ curl http://172.17.0.2:80 -> this is the container IP - does not open through browser

Hello Docker Swarm!

Running in test mode.

Served by: be93b0268b1d

[vagrant@docker1 ~]$ curl http://192.168.99.101:8080 -> this is the Docker host IP that is supposed to open through browser - as well without success

Hello Docker Swarm!

Running in test mode.

Served by: be93b0268b1d`
4snok avatar
es flag
please attache `docker run` command you used to spin up a container.
query_question avatar
cn flag
Just added. Thanks!
djdomi avatar
za flag
why not use nginx as reverse proxy?
djdomi avatar
za flag
it seems that it is based on apache. but all new and required information shall be inserted into your question alby editing it,never post it as a commentary
query_question avatar
cn flag
@djdomi, I have updated the post with the outcomes from curl in CMD and how the same is not opened in browser. Thanks!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.