Skip to content

docker run: specify cgroup namespace mode with --cgroupns - #2024

Merged
thaJeztah merged 1 commit into
docker:masterfrom
rgulewich:1988-run-cgroupns-mode
Feb 11, 2020
Merged

docker run: specify cgroup namespace mode with --cgroupns#2024
thaJeztah merged 1 commit into
docker:masterfrom
rgulewich:1988-run-cgroupns-mode

Conversation

@rgulewich

Copy link
Copy Markdown
Contributor

- What I did

This adds the --cgroupns=host|private option to docker run to allow setting the cgroup namespace mode. Fixes#1988

- How I did it

Largely by copying the code for userns and ipc modes.

- How to verify it

docker run --cgroupns=private against a daemon that's running with --default-cgroupns-mode=host.

- Description for the changelog

docker run: allow specifying cgroup namespace mode with --cgroupns

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

Cute kitten

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

Looks good, but CI failing

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from f39912d to b560da6CompareJuly 30, 2019 16:50
@GordonTheTurtle

Copy link
Copy Markdown

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "1988-run-cgroupns-mode" git@github.com:rgulewich/cli.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842358791888editor openschange each 'pick' to 'edit'save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@codecov-io

codecov-io commented Jul 30, 2019

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@2079e74). Click here to learn what that means.
The diff coverage is 80%.

@@ Coverage Diff @@## master #2024 +/- ##
=========================================
Coverage ? 56.79% =========================================
Files ? 311 Lines ? 21849 Branches ? 0 =========================================
Hits ? 12410 Misses ? 8523 Partials ? 916

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from bd828fd to 0883b2aCompareJuly 30, 2019 17:27
@rgulewich

Copy link
Copy Markdown
ContributorAuthor

Looks good, but CI failing

@AkihiroSuda - Fixed CI failures related to my changes - TestSigProxyWithTTY() is failling, but as far as I can tell, the failure is unrelated.

@kolyshkin

Copy link
Copy Markdown
Contributor

TestSigProxyWithTTY() is failling

@rgulewich might be fixed by #2016, could you please rebase?

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 0883b2a to 4c4bb53CompareJuly 31, 2019 02:44
@rgulewich

Copy link
Copy Markdown
ContributorAuthor

@kolyshkin - That did it, thanks!

Comment threade2e/container/run_test.go Outdated
environment.SkipIfCgroupNamespacesNotSupported(t)

result := icmd.RunCommand("docker", "run", "--cgroupns=private", "--rm", fixtures.AlpineImage,
"sh", "-c", "[[ $(cat /proc/1/cgroup | grep memory | cut -d: -f 3) == '/' ]]")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps rewrite this to not depend on bash? Also, looks like a single grep is sufficient, e.g.

grep -q ':memory:/$' /proc/1/cgroup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Updated - PTAL.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@thaJeztahthaJeztah 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.

Thanks! left some comments inline

Comment threadcli/command/container/opts.go Outdated
Comment threadcli/command/container/opts.go
Comment threaddocs/reference/commandline/create.md Outdated
--cap-add value Add Linux capabilities (default [])
--cap-drop value Drop Linux capabilities (default [])
--cgroupns string Cgroup namespace to use
'host': Run the container in the Docker host's cgroup namespace

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.

Might be slightly easier to read if the descriptions are aligned;

 --cgroupns string Cgroup namespace to use 'host': Run the container in the Docker host's cgroup namespace 'private': Run the container in its own private cgroup namespace '': Use the default Docker daemon cgroup namespace specified by the "--default-cgroupns-mode" option (default)

Comment threaddocs/reference/commandline/run.md
Comment threadman/docker-run.1.md
Comment threadman/dockerd.8.md Outdated

**--default-cgroupns-mode**="**host**|**private**"
Set the default cgroup namespace mode for newly created containers. The argument
can either be **host** or **private**.

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.

Should we describe the default here as well?

}

cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)
if !cgroupnsMode.Valid() {

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.

Thinking about this; I'm a bit on the fence if we should validate this on the client side, or just leave it to the daemon to return an error if an invalid value was provided. OTOH, these values likely won't change in future, so perhaps it's ok

@kolyshkin wdyt?

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 think it's ok for now, given that it likely won't change in future, but I'll open a follow-up issue after this is merged to discuss this

@albersalbers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

bash completion LGTM, thanks.

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

needs rebase

@thaJeztahthaJeztah 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.

thanks for updating! (and sorry for the delay 😞) I left one comment about the docker-compose schema version (hoping #2073 will be merged soon), and a suggestion for the flag description output for --help.

Otherwise looks good to me!

Comment threadcli/compose/schema/data/config_schema_v3.8.json Outdated
Comment threadcli/command/container/opts.go Outdated
}

cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)
if !cgroupnsMode.Valid() {

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 think it's ok for now, given that it likely won't change in future, but I'll open a follow-up issue after this is merged to discuss this

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 602452f to fdeb2fdCompareSeptember 10, 2019 04:15
@rgulewich

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah - Updated with your changes. Mind taking a look?

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch 2 times, most recently from 977f2ad to 88aba22CompareSeptember 16, 2019 19:00
@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 88aba22 to 306338fCompareSeptember 30, 2019 20:54
@rgulewich

Copy link
Copy Markdown
ContributorAuthor

@thaJeztah / @kolyshkin - Mind taking a look? Thanks!

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

@thaJeztah PTAL?

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

needs rebase

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 306338f to 298d9cdCompareOctober 25, 2019 18:42
@rgulewich

Copy link
Copy Markdown
ContributorAuthor

Rebased. @thaJeztah, mind taking a look?

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 298d9cd to 15c01bbCompareNovember 11, 2019 22:29
@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 15c01bb to 5afc093CompareDecember 18, 2019 22:25
@AkihiroSuda

Copy link
Copy Markdown
Collaborator

ping @thaJeztah

@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from 5afc093 to e0d3e04CompareJanuary 15, 2020 21:01

@thaJeztahthaJeztah 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

@silvin-lubeckisilvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks Good To Me 🐯

Signed-off-by: Rob Gulewich <rgulewich@netflix.com>
@rgulewich
rgulewichforce-pushed the 1988-run-cgroupns-mode branch from e0d3e04 to 5ad1d4dCompareJanuary 29, 2020 22:51
@AkihiroSuda

Copy link
Copy Markdown
Collaborator

CI failure seems unrelated


=== Failed
=== FAIL: e2e/image TestPushWithContentTrustUnreachableServer (0.37s)
push_test.go:323: assertion failed: Command: docker tag registry:5000/alpine:3.6 registry:5000/trust-push-unreachable:latest
ExitCode: 1
Error: exit status 1
Stdout: Stderr: error during connect: Post http://docker/v1.40/images/registry:5000/alpine:3.6/tag?repo=registry%3A5000%2Ftrust-push-unreachable&tag=latest: command [ssh -o ControlMaster=auto -o ControlPath=/root/.docker/%r@%h:%p -l penguin 172.20.0.2 -- docker system dial-stdio] has exited with exit status 255, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=
Failures:
ExitCode was 1 expected 0
Expected no error

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

CI green

@thaJeztah

Copy link
Copy Markdown
Member

Whoop! Let's merge!

@AkihiroSuda if you're able to assist with #2303 (that's related to CI being really flaky currently)

Sign up for freeto 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.

docker run flag for overriding daemon default-cgroupns-mode

8 participants

@rgulewich@AkihiroSuda@GordonTheTurtle@codecov-io@kolyshkin@thaJeztah@albers@silvin-lubecki