Assign a stable but unique MAC address to each container
authorMatt Palmer <mpalmer@hezmatt.org>
Tue, 19 Apr 2016 20:05:43 +0000 (06:05 +1000)
committerMatt Palmer <mpalmer@hezmatt.org>
Tue, 19 Apr 2016 20:05:43 +0000 (06:05 +1000)
This does Very Good Things for IPv6 addresses (at least on versions of
Docker that aren't [buggy](https://github.com/docker/docker/issues/17739)).
You get an IPv6 address which doesn't change on each reboot, and at the same
time you don't get different containers having the same IPv6 address at
different times.  Wins all round!

launcher

index ed91e797fbcb28c6cc9a3402339f8616ca372a09..0a7791142c85ea3556112cc4a7bb3cfa1c1662b0 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -528,9 +528,12 @@ run_start(){
      # docker added more hostname rules
      hostname=${hostname/_/-}
 
+     mac_address="--mac-address $(echo $hostname | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')"
+
      set -x
      $docker_path run $user_args $links $attach_on_run $restart_policy "${env[@]}" -h "$hostname" \
-        -e DOCKER_HOST_IP=$docker_ip --name $config -t $ports $volumes $docker_args $run_image $boot_command
+        -e DOCKER_HOST_IP=$docker_ip --name $config -t $ports $volumes $mac_address $docker_args \
+        $run_image $boot_command
 
    )
    exit 0