diff --git a/README.md b/README.md index dc4ce8f..8cd7541 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,10 @@ Project homepage: [https://github.com/iamluc/docker-hostmanager](https://github. The easiest way is to use the docker image ```console -$ docker run -d --name docker-hostmanager -v /var/run/docker.sock:/var/run/docker.sock -v /etc/hosts:/hosts iamluc/docker-hostmanager +$ docker run -d --name docker-hostmanager --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /etc/hosts:/hosts iamluc/docker-hostmanager ``` -*TIPS* - -To start automatically your container with your computer, add the option `--restart=always` +*Note: the `--restart=always` option will make the container start automatically with your computer (recommended).* #### Mac OS diff --git a/src/Synchronizer.php b/src/Synchronizer.php index 2daa3d2..464489e 100644 --- a/src/Synchronizer.php +++ b/src/Synchronizer.php @@ -120,7 +120,7 @@ private function getHostsLines(Container $container) if (!empty($inspection['NetworkSettings']['IPAddress'])) { $ip = $inspection['NetworkSettings']['IPAddress']; - $lines[] = $ip.' '.implode(' ', $this->getContainerHosts($container)); + $lines[$ip] = implode(' ', $this->getContainerHosts($container)); } // Networks @@ -136,10 +136,14 @@ private function getHostsLines(Container $container) $hosts[] = $alias.'.'.$networkName; } - $lines[] = $ip.' '.implode(' ', $hosts); + $lines[$ip] = sprintf('%s%s', isset($lines[$ip]) ? $lines[$ip].' ' : '', implode(' ', $hosts)); } } + array_walk($lines, function (&$host, $ip) { + $host = $ip.' '.$host; + }); + return $lines; }