Skip to content

Commit

Permalink
Merge pull request iamluc#28 from kevin-verschaeve/feature/one-line-p…
Browse files Browse the repository at this point in the history
…er-ip

merge hosts with same ip onto one line in hosts file
  • Loading branch information
iamluc authored Jul 26, 2016
2 parents 1821ec6 + ec52d26 commit c4b4b3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions src/Synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit c4b4b3c

Please sign in to comment.