TestDaemonHostGatewayIP verifies that when a magic string "host-gateway" is passed to ExtraHosts (--add-host) instead of an IP address, its value is set to 1. Daemon config flag value specified by host-gateway-ip or 2. IP of the default bridge network and is added to the /etc/hosts file
(t *testing.T)
| 134 | // 2. IP of the default bridge network |
| 135 | // and is added to the /etc/hosts file |
| 136 | func TestDaemonHostGatewayIP(t *testing.T) { |
| 137 | skip.If(t, testEnv.IsRemoteDaemon) |
| 138 | skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| 139 | t.Parallel() |
| 140 | |
| 141 | ctx := testutil.StartSpan(baseContext, t) |
| 142 | |
| 143 | // Verify the IP in /etc/hosts is same as host-gateway-ip |
| 144 | d := daemon.New(t) |
| 145 | // Verify the IP in /etc/hosts is same as the default bridge's IP |
| 146 | d.StartWithBusybox(ctx, t, "--iptables=false", "--ip6tables=false") |
| 147 | c := d.NewClientT(t) |
| 148 | cID := container.Run(ctx, t, c, |
| 149 | container.WithExtraHost("host.docker.internal:host-gateway"), |
| 150 | ) |
| 151 | res, err := container.Exec(ctx, c, cID, []string{"cat", "/etc/hosts"}) |
| 152 | assert.NilError(t, err) |
| 153 | assert.Assert(t, is.Len(res.Stderr(), 0)) |
| 154 | assert.Equal(t, 0, res.ExitCode) |
| 155 | resp, err := c.NetworkInspect(ctx, "bridge", client.NetworkInspectOptions{}) |
| 156 | assert.NilError(t, err) |
| 157 | assert.Check(t, is.Contains(res.Stdout(), resp.Network.IPAM.Config[0].Gateway.String())) |
| 158 | c.ContainerRemove(ctx, cID, client.ContainerRemoveOptions{Force: true}) |
| 159 | d.Stop(t) |
| 160 | |
| 161 | // Verify the IP in /etc/hosts is same as host-gateway-ip |
| 162 | d.StartWithBusybox(ctx, t, "--iptables=false", "--ip6tables=false", "--host-gateway-ip=6.7.8.9") |
| 163 | cID = container.Run(ctx, t, c, |
| 164 | container.WithExtraHost("host.docker.internal:host-gateway"), |
| 165 | ) |
| 166 | res, err = container.Exec(ctx, c, cID, []string{"cat", "/etc/hosts"}) |
| 167 | assert.NilError(t, err) |
| 168 | assert.Assert(t, is.Len(res.Stderr(), 0)) |
| 169 | assert.Equal(t, 0, res.ExitCode) |
| 170 | assert.Check(t, is.Contains(res.Stdout(), "6.7.8.9")) |
| 171 | c.ContainerRemove(ctx, cID, client.ContainerRemoveOptions{Force: true}) |
| 172 | d.Stop(t) |
| 173 | } |
| 174 | |
| 175 | // TestRestartDaemonWithRestartingContainer simulates a case where a container is in "restarting" state when |
| 176 | // dockerd is killed (due to machine reset or something else). |
nothing calls this directly
no test coverage detected
searching dependent graphs…