Tips n Tricks: 02-BUT How the hell do I access the service in Docker
Prologue
For the unininitiated in this gurukul, I have been approached by few intelligent and erterprising Gen-Z developers (thats what I prefer calling those buddies) to teach and initiate them to become experts in Docker also, BUT BUT BUT... NOT in a Fast Track mode but Slow and Steady mode. AND hence dear friends, I would be sticking to One Tip in a Day in this Tips and Tricks series.
Even my Boss (aka Bhole Baba who also takes the Rudra form of Mahakaal at times) has given the diktat to Mohsin (aka Nandi) to stand with a stick if in case I dare to deviate from the plan ??
So here I am, in this series, with the next tip for today
The problem statement
While my buddies completed:
The Million Dollar Question came:
How do I access the service running in the docker container
Hmm... Let me give some background / sysadmin concepts:
How does any service expose itself?
领英推荐
Obvisouly, with TCP/UDP ports.
100% Correct! HTTP services listen to TCP/80, MySQL listens to TCP/3306, DNS might listen on UDP/53.
Now if this is clear, the Mongo container running in your local environment would be listening to TCP/27017
But that TCP/27017 port is exposed inside the container and not visible outside locally
Correct. Absolutely correct. And the trick is..
... While starting the container
... Map the port inside with a port of choice outside
docker run -p 8121:80 nginx
The flag -p does the port-mapping. In the above example, it is mapping the local port 8121/tcp with the port 80/tcp running inside the container.
and because of this mapping, you can now open your favourite browser and fire: http:/127.0.0.1:8121 and you would see the Nginx WELCOME PAGE.
Yeaaa... We have done it. Now go out and try this with different services using different docker images.
Thats it for today. ENJOY ??
#docker #devOps