szabgab
szabgab

Reputation: 6302

docker with public IP as a client

I have a host with 10.1.1.2 and I'd like to create a docker container on it that will have the IP address 10.1.1.3 and that will be able to ping (and later to send its syslog) to an external machine on the same network. (eg. 10.1.1.42). I'd also like the packets to arrive from 10.1.1.3. So as far as I understand no NAT.

I am not interested in inbound network connections to the docker container but outbound.

Upvotes: 0

Views: 46

Answers (1)

larsks
larsks

Reputation: 311406

There is apparently an unresolved issue for this feature right now, so the only current solution is to manually create the necessary iptables rules after launching your container. E.g., something like:

iptables -t nat -I POSTROUTING 1 -s <container_ip> -j SNAT --to-source 10.1.1.3

You will also need to add that address to an interface on your host:

ip addr add 10.1.1.3/24 dev eth0

Upvotes: 1

Related Questions