mirror of
https://github.com/moby/moby.git
synced 2025-07-29 07:21:35 +03:00
Add flag --host
to service create
and --host-add/--host-rm
to service update
This fix tries to address 27902 by adding a flag `--host` to `docker service create` and `--host-add/--host-rm` to `docker service update`, so that it is possible to specify extra `host:ip` settings in `/etc/hosts`. This fix adds `Hosts` in swarmkit's `ContainerSpec` so that it is possible to specify extra hosts during service creation. Related docs has been updated. An integration test has been added. This fix fixes 27902. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@ -1028,3 +1028,26 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {
|
||||
c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSwarmSuite) TestExtraHosts(c *check.C) {
|
||||
d := s.AddDaemon(c, true, true)
|
||||
|
||||
// Create a service
|
||||
name := "top"
|
||||
_, err := d.Cmd("service", "create", "--name", name, "--host=example.com:1.2.3.4", "busybox", "top")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// Make sure task has been deployed.
|
||||
waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
|
||||
|
||||
// We need to get the container id.
|
||||
out, err := d.Cmd("ps", "-a", "-q", "--no-trunc")
|
||||
c.Assert(err, checker.IsNil)
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
// Compare against expected output.
|
||||
expectedOutput := "1.2.3.4\texample.com"
|
||||
out, err = d.Cmd("exec", id, "cat", "/etc/hosts")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
|
||||
}
|
||||
|
Reference in New Issue
Block a user