close
Skip to content

Display a warn message when there is binding ports and net mode is host - #35510

Merged
vdemeester merged 1 commit into
moby:masterfrom
boaz0:fix_35500
Feb 19, 2018
Merged

Display a warn message when there is binding ports and net mode is host#35510
vdemeester merged 1 commit into
moby:masterfrom
boaz0:fix_35500

Conversation

@boaz0

@boaz0 boaz0 commented Nov 15, 2017

Copy link
Copy Markdown
Contributor

- What I did
Fixes #35500

When a container is created if --network is set to host all the ports in the container are bound to the host. Thus, when adding -p or --publish to the command line is meaningless.

Unlike docker run and docker create, docker service create returns an error message when network mode is host and port bindings are given.

- How I did it

This patch however suggests to send a warning message to the client when
such a case occurs.

By adding it to the warnings returned from verifyPlatformContainerSettings

- How to verify it

Added integration test to that so just run make test-integration.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but functionally looks to be working :)

$ docker run -dit --name foo --network=host -p 80:80 busybox
WARNING: Setting published IPs is useless when network mode is set to host
4d09a6ebc335a6c89a4c4f812d234d41c4cf6aa9040d8867bd7d852d4f01792b

Comment thread daemon/container.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, had to laugh a bit about your choice of wording 😄

useless

I'll try to come up with an alternative 👍

Comment thread daemon/container.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the error here, and return? It "looks" safe in this case, but it's best practice to handle errors;

platformWarns, err := verifyPlatformContainerSettings(daemon, hostConfig, config, update)
if err != nil {
    return nil, err
}

Now that platformWarns no longer contains "just" platform-specific warnings, we should probably rename it to something more generic (just warnings?)

Comment thread daemon/container.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the above; I don't think host networking is supported on Windows (although with LCOW .. perhaps it's still relevant here); I'll have to check that one. If not supported on Windows we should probably move it in verifyPlatformContainerSettings()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @johnstep @jhowardmsft could you have a look? ^^

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msabansal Probably one for you to answer. PTAL.

@vdemeester vdemeester left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸

Comment thread daemon/container.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Saw you slightly changed the message; thinking a bit more about wording; would this work perhaps;

Published ports are discarded when using host network mode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem.

Comment thread integration/container/create_test.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be a unit-test instead of an integration test?

@boaz0

boaz0 commented Feb 15, 2018

Copy link
Copy Markdown
Contributor Author

ping @thaJeztah @jhowardmsft

@lowenna

lowenna commented Feb 15, 2018

Copy link
Copy Markdown
Member

Seems OK, but I'd like @msabansal from the networking team here to confirm.

@msabansal

Copy link
Copy Markdown
Contributor

LGTM.

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread daemon/container_test.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could use Godoc conventions: s/This tests/TestContainerWarningHostAndPublishPorts tests/

@vdemeester

Copy link
Copy Markdown
Member
daemon/container_test.go:1::warning: file is not gofmted with -s (gofmt)

@codecov

codecov Bot commented Feb 18, 2018

Copy link
Copy Markdown

Codecov Report

Merging #35510 into master will increase coverage by 0.04%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #35510      +/-   ##
==========================================
+ Coverage   34.27%   34.32%   +0.04%     
==========================================
  Files         609      611       +2     
  Lines       45287    45489     +202     
==========================================
+ Hits        15523    15612      +89     
- Misses      27816    27870      +54     
- Partials     1948     2007      +59
Impacted Files Coverage Δ
daemon/container.go 25.27% <71.42%> (+5.73%) ⬆️
pkg/discovery/file/file.go 90.38% <0%> (-5.77%) ⬇️
restartmanager/restartmanager.go 33.33% <0%> (-3.18%) ⬇️
daemon/cluster/executor/container/adapter.go 9.16% <0%> (-0.84%) ⬇️
builder/fscache/fscache.go 58.84% <0%> (-0.58%) ⬇️
daemon/graphdriver/devmapper/deviceset.go 39.85% <0%> (-0.21%) ⬇️
vendor/github.com/docker/distribution/errors.go 21.42% <0%> (ø)
vendor/github.com/docker/distribution/registry.go 52.08% <0%> (ø)
daemon/daemon.go 4.5% <0%> (+0.15%) ⬆️
pkg/archive/archive.go 68.05% <0%> (+0.63%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5e7537...6e78fdb. Read the comment docs.

When a container is created if "--network" is set to "host" all the
ports in the container are bound to the host.
Thus, adding "-p" or "--publish" to the command-line is meaningless.

Unlike "docker run" and "docker create", "docker service create" sends
an error message when network mode is host and port bindings are given

This patch however suggests to send a warning message to the client when
such a case occurs.

The warning message is added to "warnings" which are returned from
"verifyPlatformContainerSettings".

Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
@vdemeester
vdemeester merged commit 35d69f1 into moby:master Feb 19, 2018
@boaz0

boaz0 commented Feb 19, 2018

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants