Reputation: 339
I have one host machine which have two ip addresses, also I have two nginx containers. How to map first ip to first nginx, and second ip to second nginx?
Upvotes: 0
Views: 138
Reputation: 3798
I'll assume that by IP you actually mean a socket, e.g. your nginx1
container will listen to the IP address #1 (let's say 1.2.3.1
) on port 8080 and your nginx2
container will listen to your IP address #2 (let's say 1.2.3.2
) on port 8081.
The option --publish
will fulfill your need. It is used with docker run
as so:
docker run -d --publish=1.2.3.1:8080:80 -name nginx1 nginx
This command will start the image nginx
as a container named nginx1
in background mode and the socket 1.2.3.1:8080
will be bound to the port 80
of the container. As for nginx2
: docker run -d --publish=1.2.3.2:8081:80 -name nginx2 nginx
.
To combine it with docker compose
you'll just need to add these options in the .yml
file and you're done!
Upvotes: 1