Skip to content

Use spf13/cobra for docker run and docker create#23159

Closed
dnephin wants to merge 2 commits intomoby:masterfrom
dnephin:integrate_cobra.docker_run
Closed

Use spf13/cobra for docker run and docker create#23159
dnephin wants to merge 2 commits intomoby:masterfrom
dnephin:integrate_cobra.docker_run

Conversation

@dnephin
Copy link
Copy Markdown
Member

@dnephin dnephin commented Jun 1, 2016

This PR builds off of #22769

As requested in #22769 (comment) this is a PoC to show that cobra and pflag will work for a more involved command like docker run.

@thaJeztah
Copy link
Copy Markdown
Member

ping @duglin @LK4D4 @vdemeester PTAL

@thaJeztah thaJeztah added the status/failing-ci Indicates that the PR in its current state fails the test suite label Jun 1, 2016
@vdemeester
Copy link
Copy Markdown
Member

Code looks good 👍 (and I like the TODOs on the flags 👼)
Tried it a little bit, seems fine but didn't have time for a complete test of the run command.

@thaJeztah
Copy link
Copy Markdown
Member

Hm, looks like I found a really weird issue;

This fails:

docker run -v /bla/bla:/foo/bar:rw,Z -dit -p 127.0.0.1:80:80 alpine sh

So does this:

docker run -it --rm alpine sh

But using "busybox" works;

docker run -v /bla/bla:/foo/bar:rw,Z -dit -p 127.0.0.1:80:80 busybox sh
docker run -it --rm busybox sh

For alpine it sends an empty command;

{
  "AttachStderr": false,
  "AttachStdin": false,
  "AttachStdout": false,
  "Cmd": null,
  "Domainname": "",
  "Entrypoint": null,
  "Env": [

  ],
..

@vdemeester
Copy link
Copy Markdown
Member

Hum some weirdies though (tried it out with @thaJeztah ) :

root@fb4c2eda9e89:/go/src/github.com/docker/docker# ./bundles/latest/binary-client/docker run -v /var:/foo:rw,Z -dit -p 127.0.0.1:80:80 busybox sh
b5424362a55dc975347e3ebb097db45ba8389f69d84e00586e230b50160af160
root@fb4c2eda9e89:/go/src/github.com/docker/docker# ./bundles/latest/binary-client/docker run -v /var:/foo:rw,Z -dit -p 127.0.0.1:80:80 alpine sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
d0ca440e8637: Pull complete 
Digest: sha256:9dd95238d7f6ac0fabafd7b52e52d8a7c63a5e5b390d27e13cb5da8ddd2f0d98
Status: Downloaded newer image for alpine:latest
./bundles/latest/binary-client/docker: Error response from daemon: No command specified.
See './bundles/latest/binary-client/docker run --help'.
root@fb4c2eda9e89:/go/src/github.com/docker/docker# ./bundles/latest/binary-client/docker run -v /var:/foo:rw,Z -dit -p 127.0.0.1:80:80 alpine sh
./bundles/latest/binary-client/docker: Error response from daemon: No command specified.
See './bundles/latest/binary-client/docker run --help'.

Looks like the command is not passed (busybox has a default command, alpine does not)

@thaJeztah
Copy link
Copy Markdown
Member

Ok we (@vdemeester) found the difference; it appears to fail if there's no default command in the image. Doing this works:

FROM alpine
CMD sh
docker build -t frommie .
docker run -it --rm frommie sh

@thaJeztah
Copy link
Copy Markdown
Member

Some more testing, and this works ok

export FOOBAR=blabla

docker run \
    -v /bla/bla:/foo/bar:rw,Z \
    -dit \
    -p 127.0.0.1:80:80 \
    -v $(docker volume create --name foobar):/foobar \
    -u 123:456 \
    --label bla=foo \
    -l bla=bar \
    -e FOOBAR \
    -e something=something \
    --memory 300m \
    --security-opt apparmor:unconfined \
    --security-opt seccomp=unconfined \
    --name cobra \
    busybox sh

@dnephin dnephin force-pushed the integrate_cobra.docker_run branch from 4825a42 to 3a7de8c Compare June 1, 2016 15:10
@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Jun 1, 2016

Oops, sorry about that. I had a fix for that issue and I forgot to push it before opening the PR.

That issue is now fixed.

@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Jun 1, 2016

docker create is implemented now as well, so more of the tests should pass

@dnephin dnephin force-pushed the integrate_cobra.docker_run branch from 25db6b0 to b93d092 Compare June 1, 2016 21:21
Comment thread api/client/container/run.go Outdated
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.

Is this something that should be in a generic spot so it can be reused by other commands?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Doesn't seem to be used anywhere else. I just moved this, it already existed before my change.

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.

hmm interesting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is trying to mimic the error message that is normally raised when a flag or value is incorrect. These two commands do a bunch of validation on the flag values after the initial parsing, where as I think many commands don't do any additional validation.

@dnephin dnephin force-pushed the integrate_cobra.docker_run branch 2 times, most recently from 02cbfad to ef96863 Compare June 2, 2016 04:30
@dnephin dnephin changed the title PoC: use spf13/cobra for docker run Use spf13/cobra for docker run Jun 2, 2016
@dnephin dnephin changed the title Use spf13/cobra for docker run Use spf13/cobra for docker run and docker create Jun 2, 2016
@dnephin dnephin removed the status/failing-ci Indicates that the PR in its current state fails the test suite label Jun 2, 2016
@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Jun 2, 2016

The build is green!

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Jun 2, 2016

needs rebase

@dnephin dnephin force-pushed the integrate_cobra.docker_run branch from ef96863 to 2096767 Compare June 2, 2016 17:25
@dnephin dnephin mentioned this pull request Jun 2, 2016
43 tasks
Move container options into a struct so that tests should pass.
Remove unused FlagSet arg from Parse
Disable interspersed args on docker run

Signed-off-by: Daniel Nephin <[email protected]>
@dnephin dnephin force-pushed the integrate_cobra.docker_run branch from 2096767 to f0a8522 Compare June 3, 2016 17:26
Return the correct status code on flag parsins errors.

Signed-off-by: Daniel Nephin <[email protected]>
@dnephin dnephin force-pushed the integrate_cobra.docker_run branch from f0a8522 to aaac5fd Compare June 3, 2016 17:39
@thaJeztah
Copy link
Copy Markdown
Member

ow; flaky/faulty test on WindowsTP5 (not related); guess this is the issue with Windows not liking filenames named #1

17:54:09 ----------------------------------------------------------------------
17:54:09 FAIL: docker_cli_build_test.go:6760: DockerSuite.TestBuildDockerignoreComment
17:54:09 
17:54:09 docker_cli_build_test.go:6791:
17:54:09     c.Fatal(err)
17:54:09 ... Error: failed to build the image: Sending build context to Docker daemon 5.632 kB

17:54:09 Step 1 : FROM busybox
17:54:09  ---> 3f1b2939d14c
17:54:09 Step 2 : ADD . /tmp/
17:54:09  ---> 78175a922461
17:54:09 Removing intermediate container e893b2ece047
17:54:09 Step 3 : RUN sh -c "(ls -la /tmp/#1)"
17:54:09  ---> Running in 14e3ac5d6f7e
17:54:09 The command 'cmd /S /C sh -c "(ls -la /tmp/#1)"' returned a non-zero code: 255

@thaJeztah
Copy link
Copy Markdown
Member

Opened #23246 for the test

@thaJeztah
Copy link
Copy Markdown
Member

Windows test will be fixed in #23248

@dnephin
Copy link
Copy Markdown
Member Author

dnephin commented Jun 3, 2016

it's green!

@thaJeztah
Copy link
Copy Markdown
Member

LGTM

@thaJeztah thaJeztah added this to the 1.12.0 milestone Jun 3, 2016
@vdemeester
Copy link
Copy Markdown
Member

Arf, needs a rebase 😓

@thaJeztah
Copy link
Copy Markdown
Member

Ah, probably because this one was merged #23241. I hoped this one would get merged first

@vdemeester
Copy link
Copy Markdown
Member

LGTM 👼
Let's carry this to merge it quick 😝

thaJeztah added a commit that referenced this pull request Jun 4, 2016
Carry #23159 : Use spf13/cobra for `docker run` and `docker create`
@dnephin dnephin deleted the integrate_cobra.docker_run branch June 4, 2016 17:05
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
Carry moby#23159 : Use spf13/cobra for `docker run` and `docker create`
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