Binding a container to a specific IP address

Until now, with the method that you learned, the containers always get bound to all the IP addresses configured on the Docker host. However, you may want to offer different services on different IP addresses. In other words, a specific IP address and port would be configured to offer a particular service. We can achieve this in Docker using the -p <ip>:<hostPort>:<containerPort> option of the docker run subcommand, as shown in the following example:

$ sudo docker run -d -p 198.51.100.73:80:80 apache292f107537bebd48e8917ea4f4788bf3f57064c8c996fc23ea0fd8ea49b4f3335  

Here, the IP address must be a valid IP address on the Docker host. If the specified IP address is not a valid IP address on the Docker ...

Get Learning Docker - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.