How to expose docker container's ip and port to outside docker host without port mapping?

+1 vote

When i started two docker containers for a same web image on one docker host.

  • two docker containers listened on the same port 8000
  • port 8000 of the two containers were mapped to different ports of docker host: 49127, 49132
  • to access the two containers from outside docker host need to be by accessing the docker host ip and port 49127 or 49132

Is there a solution to access a docker container from outside docker host by its ip and port, x.x.x.x:8000, without port mapping?

Aug 2, 2018 in Docker by Hannah
• 14,080 points
1,020 views
When you have the option of port mapping why would you want to use anything else?

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote

you can accomplish this with IP aliasing on the host.

First, add a virtual interface on the host that has a different IP address than the primary interface. We'll call the primary interface eth0 with IP 10.0.0.10, and the virtual interface eth0:1 with IP address 10.0.0.11.

 ifconfig eth0:1 10.0.0.11 netmask 255.255.255.0 up 

Now run the containers and map port 5000 to the corresponding interface. For example:

docker run -p 10.0.0.10:8000:8000 -name container1 <someimage> <somecommand>
docker run -p 10.0.0.11:8000:8000 -name container2 <someimage> <somecommand>

Now you can access each container on port 8000 using different IP addresses externally.

answered Aug 2, 2018 by Kalgi
• 35,720 points

Related Questions In Docker

0 votes
1 answer

How to obtain the Docker container's IP address from the host?

This can be done by executing the ...READ MORE

answered Jul 16, 2018 in Docker by Sophie may
• 9,050 points
85 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to remove old Docker containers

There is a new feature in Docker 1.13.x called Docker ...READ MORE

answered Jul 18, 2018 in Docker by Kalgi
• 2,620 points
21 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,100 points
56 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,100 points

edited Oct 16, 2018 by lina 1,925 views
+1 vote
2 answers

How to run docker containers on different machines

You can use labels and selectors for ...READ MORE

answered Oct 23, 2018 in Docker by Laila
38 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.