Friday, July 17, 2015

Giving Docker containers static ip addresses

https://it-offshore.co.uk/linux/debian/36-giving-docker-containers-static-ip-addresses

I am currently using Docker to run a Debian build environment with a separate nginx container for a local apt repository (with both containers sharing a data-only container). At the moment there is no functionality in Docker to add a static ip address. It is expected to arrive in docker 1.7 viadocker/libnetwork - see also the Docker Blog. In the meantime the following works:
Assuming a default gateway ip address of 192.168.1.1:
BASH CODE
  sudo bash -c "curl https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework > /usr/local/bin/pipework" sudo chmod +x /usr/local/bin/pipework sudo pipework br0 container-name 192.168.1.100/24@192.168.1.1  
You will no longer be able to use docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" to find the containers ip address.
script to create docker data-only containers + a container with an optional static ip address. If the script is re-run to create a container-name that already exists - it will optionally create container-name2 then container-name3 etc...

- The Old Way (pre v 1.0) -
http://shellfu.com/2014/11/docker-assigning-static-ip-addresses-to-containers/


No comments: