I have a server with several virtual machines running. I am starting a container with Jira installation and i need the container to be assigned with different address from the DHCP and not use the host IP address. I am a noobie so please explain
The technique suggested in @ad22's answer requires a custom build of the Docker engine that uses a fork of libnetwork. Now, more than four years after that hack was developed, the DHCP feature has still not been merged into the standard Docker engine, and the fork has fallen far behind the mainline code.
Since late 2019, it has been possible to assign IP addresses to Docker containers with DHCP using devplayer0's docker-net-dhcp
plugin, which works with the standard Docker engine. When you create a new container, this plugin starts a Busybox udhcpc client to obtain a DHCP lease, then runs udhcpc (in a process outside the container's PID namespace) to renew the lease as needed.
As found in the other answer, using the macvlan
will not enable the container to obtain addresses from DHCP. The functionality to obtain addresses from DHCP is experimental (this was created by someone associated with the docker libnetwork project)
https://gist.github.com/nerdalert/3d2b891d41e0fa8d688c
It suggests compiling the changes into the docker binary and then running
docker network create -d macvlan \
--ipam-driver=dhcp \
-o parent=eth0 \
--ipam-opt dhcp_interface=eth0 mcv0
Since this requires re-compiling the binary, an alternate solution could be to assign static IP addresses to all your containers using the "--ip" option to docker run/compose, and get a DNS entry for your hostname assigned to this IP, and also ensure that the IP can never be assigned through DHCP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With