Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 11, 2020

Conversation

rgulewich
Copy link
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
Collaborator

Looks good, but CI failing

@GordonTheTurtle
Copy link

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~842358791888
editor opens
change 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
Copy link

codecov-io commented Jul 30, 2019

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
Copy link
Contributor Author

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
Contributor

TestSigProxyWithTTY() is failling

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

@rgulewich
Copy link
Contributor Author

@kolyshkin - That did it, thanks!

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
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
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated - PTAL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@thaJeztah thaJeztah left a comment

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

cli/command/container/opts.go Outdated Show resolved Hide resolved
cli/command/container/opts.go Show resolved Hide resolved
@@ -29,6 +29,10 @@ Options:
--blkio-weight-device value Block IO weight (relative device weight) (default [])
--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
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)

docs/reference/commandline/run.md Show resolved Hide resolved
man/docker-run.1.md Show resolved Hide resolved
man/dockerd.8.md Outdated
@@ -177,6 +178,10 @@ $ sudo dockerd --add-runtime runc=runc --add-runtime custom=/usr/local/bin/my-ru
**-D**, **--debug**=*true*|*false*
Enable debug mode. Default is false.

**--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
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?

@@ -471,6 +473,11 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
return nil, errors.Errorf("--userns: invalid USER mode")
}

cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)
if !cgroupnsMode.Valid() {
Copy link
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
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

Copy link
Collaborator

@albers albers left a comment

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
Collaborator

needs rebase

Copy link
Member

@thaJeztah thaJeztah left a comment

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!

cli/compose/schema/data/config_schema_v3.8.json Outdated Show resolved Hide resolved
cli/command/container/opts.go Outdated Show resolved Hide resolved
@@ -471,6 +473,11 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
return nil, errors.Errorf("--userns: invalid USER mode")
}

cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)
if !cgroupnsMode.Valid() {
Copy link
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
Copy link
Contributor Author

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

@rgulewich rgulewich force-pushed the 1988-run-cgroupns-mode branch 2 times, most recently from 977f2ad to 88aba22 Compare September 16, 2019 19:00
@rgulewich
Copy link
Contributor Author

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

@AkihiroSuda
Copy link
Collaborator

@thaJeztah PTAL?

@AkihiroSuda
Copy link
Collaborator

needs rebase

@rgulewich
Copy link
Contributor Author

Rebased. @thaJeztah, mind taking a look?

@AkihiroSuda
Copy link
Collaborator

ping @thaJeztah

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

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>
@AkihiroSuda
Copy link
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
Collaborator

CI green

@thaJeztah
Copy link
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 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.

docker run flag for overriding daemon default-cgroupns-mode
8 participants