I have created an image of my application and run a container on one machine. my inner container port is: 8081.
I see that the container is running.
I would like to talk with that container from another machine from an application that doesnt run as a docker container, with a GET request, all the machines in the same VLAN.
How do I communicate with that docker container from another machine? with which ip and port ?
in the first trial – I run the container with the exposed port as the inner port :
sudo docker run -d -p 8081:8081 myimage:2.0
in my second trial I run the container like this:
sudo docker run -d -p 80:8081 myimage:2.0
_______
Update:
so I would like to share what was the problem with my container:
so initially I was adding at the end of my docker file the following line so that it will not exit immediately.:
CMD tail -f /dev/null
it seems to run however only when adding in my sh script
while true; do sleep 1000; done
I was able to access my container.
2
Answers
In my case I was running sh file from the Dockerfile. Adding: "while true; do sleep 1000; done" to my sh file solved the issue.
this is in addition to Exposing the port with the -p : flag
Exposing the port with the
-p <outside>:<inside>
flag will pass through the all traffic on the outside port of your machine running the container to the inside port in your container. So you can just communicate with the container through either port 80 or port 8081 depending on what command you start your container with. The ip will be the ip of the machine running the container.