so i have been using docker for while though i am working on it for first time. I am trying to make a web server on raspberry pi . it contains 2 containers . 1 container consists of nginx server which contains website and 2 second container contains a port of mysql . both containers communicates with each other through bridge. and every thing works fine but the problem is that ip address (220.127.116.11) of docker only works on host system. how can i make the website visible to another system which is not on host local network. like anyone from anywhere should be able to use or access website? Any suggestions please help
map the nginx port to the host (raspberry pi address) and share THAT
then the users are talking to the PI, not directly to the container…
that is what docker is all about… no install on the pi, but you get the function
When you do the docker run expose port 80 or 3306, to the host and then hit the host address on port 80 like the following:
docker run -dit -p 80:80 --name container_name image_name
This is if you have an ip address on your network such as 192.168.20.12 this being your network. Then it forwards it to the container on the 18.104.22.168 container or whatever your local ip for the container is.
80:80 is the key this exposes port 80 on the container and port 80 to the host there for if you hit the host ip it will forward the request to the container. Providing you don’t have anything running on port 80 of the host.
I think this is the way it works but I could be wrong…The -dit detached your session from the container so that it runs on it’s own.
Hope this helps
Correct the -p parameter sets up port forwarding from the host port to the Container port so that you can use the host IP address to execute the application as if it were installed but having the container do all the work