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

Adds flag modifying pull behavior for running and creating containers #1498

Merged
merged 6 commits into from
May 6, 2019

Conversation

zmackie
Copy link
Contributor

@zmackie zmackie commented Nov 5, 2018

Should close issue moby/moby#34394

- What I did

- How I did it

  • Adds a new config field, createOptions.pull which forks the execution of container.createContainer to either pull the image if it does not exist at all locally --pull=missing, always try and update the image --pull=always, or never try and update the image, only using images that already exist on the local machine --pull=never

Both docker run and docker create can consume this flag.

- How to verify it

  • Run docker run and docker create with the flag. Notice that pulls images or does not, depending on the behavior specified in the flag. Running those commands without the flag should maintain the current behavior.

- Description for the changelog

Adds flag modifying pull behavior for running and creating containers (Pull if Missing, Pull Always, Pull Never)

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

@zmackie
Copy link
Contributor Author

zmackie commented Nov 5, 2018

Hey docker folks. This is my first PR to the project (👋 ). It's likely deficient on tests (I especially wasn't sure about any kind of integration or e2e testing that needed to happen. Let me know what ya'll think.

@zmackie zmackie force-pushed the 34394-run-pull-flag branch from 0934964 to 58517d0 Compare November 6, 2018 14:16
@codecov-io
Copy link

codecov-io commented Nov 6, 2018

Codecov Report

Merging #1498 into master will increase coverage by 0.01%.
The diff coverage is 61.11%.

@@            Coverage Diff             @@
##           master    #1498      +/-   ##
==========================================
+ Coverage   56.75%   56.77%   +0.01%     
==========================================
  Files         309      309              
  Lines       21658    21668      +10     
==========================================
+ Hits        12292    12301       +9     
+ Misses       8469     8468       -1     
- Partials      897      899       +2

@lanoxx
Copy link

lanoxx commented Nov 12, 2018

Nice work. I hope the docker folks will merge this.

@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 "34394-run-pull-flag" git@github.com:Zanadar/cli.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354135168
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.

@zmackie zmackie force-pushed the 34394-run-pull-flag branch from f31fec0 to 053b7b4 Compare November 20, 2018 11:58
gerhard added a commit to thechangelog/changelog.com that referenced this pull request Dec 31, 2018
Using the pull command explicitly until the docker CLI supports this
natively. re docker/cli#1498

[#162511937]
@svenstaro
Copy link

What's the work remaining in order to get this merged?

@zmackie
Copy link
Contributor Author

zmackie commented Jan 22, 2019

AFAIK nothing (but it’s been a while since I opened this so I may have forgotten). Maybe project folks have a different opinion?

@svenstaro
Copy link

@GordonTheTurtle could you take a look?

@Morl99
Copy link

Morl99 commented Feb 11, 2019

@Zanadar can you try to increase the test coverage, you are slightly falling short, as per the above Check. I would love to see this feature merged, it is really useful!

@cpuguy83
Copy link
Collaborator

Overall this looks good, but I think we can clean up the implementation a bit.

@cpuguy83
Copy link
Collaborator

Also keep in mind pull-policy=always only really works for moving tags (such as latest).

Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

Should we error out early if pull=always and the pull failed?

@@ -194,31 +205,59 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig
}

//create the container
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, opts.name)
var response container.ContainerCreateCreatedBody
if opts.pull == PullImageMissing { // Pull image only if it does not exist locally. Default.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can do this flow and it will clean up quite a bit:

warning, psuedo-code:

if PullImageAlways {
  pull()
}

err := createContainer()
if IsNotfound(err) && PullImageMissing {
  pull()
}

createContainer()

Copy link
Contributor Author

@zmackie zmackie Feb 16, 2019

Choose a reason for hiding this comment

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

Latest commit improves the flow per suggestion, but I'm not sure I've got it quite right...will work at it a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing I'm not certain on is whether we should error in the case that the image is not found locally and the "never pull" option is selected? In which case the flow becomes more like so:

if PullImageAlways {
  pull()
}

err := createContainer()
if err {
  if IsNotfound(err) && PullImageMissing {
    pull()
    createContainer()
  }
  return err // we won't be pulling so just return whatever err we got
}

This also saves trying to create the container twice in the "never pull" case (ie only try to create again in the case where we might pull).

@zmackie
Copy link
Contributor Author

zmackie commented Feb 16, 2019

Also keep in mind pull-policy=always only really works for moving tags (such as latest).

That's probably something that would have to be left to users, though, right? We can't necessarily know whether a tag is moving or not.

@cpuguy83
Copy link
Collaborator

Right.

@zmackie zmackie force-pushed the 34394-run-pull-flag branch from f0b476c to a281095 Compare February 17, 2019 14:44
@zmackie
Copy link
Contributor Author

zmackie commented Feb 17, 2019

Should we error out early if pull=always and the pull failed?

This is now handled in the first block: https://github.com/docker/cli/pull/1498/files#diff-477f60a1b609e77fdca573fd8bd7b0c9R210

@zmackie
Copy link
Contributor Author

zmackie commented Feb 17, 2019

@cpuguy83 Okay I cleaned things up a fair bit. I'd love a review pass on the tests and your thoughts on how we handle the error case when "never pull" is selected (see above).

@robbaman
Copy link

Is there a reason why the latest version of Docker Desktop on Windows still has version 19.03 of the CLI? According to this thread it seems 19.09 should've been worked on/ready for about 6 months already.

@jcchavezs
Copy link

Could the default behaviour be overriden by an env var? I could come up with a PR.

@gitnik
Copy link

gitnik commented Apr 22, 2020

This is still not available in engine version 19.03.08 in Docker for Mac. Any estimate when this will be available?

@thaJeztah
Copy link
Member

Next release (20.xx)

@nickgrealy
Copy link

nickgrealy commented Jul 23, 2020

Two (stupid?) questions:

  1. Is it possible to have this work with docker pull <someimage> commands too?

e.g. docker pull --pull=always nginx

  1. Is it possible to have --pull=newer - to pull the latest version of an image, only if it's newer in the repo?

@FernandoMiguel
Copy link

Two (stupid?) questions:

  1. Is it possible to have this work with docker pull <someimage> commands too?

e.g. docker pull --pull=always nginx

  1. Is it possible to have --pull=newer - to pull the latest version of an image, only if it's newer in the repo?

I don't understand your first one.
The second one is the behaviour of pull.

@robbaman
Copy link

Jut got a new version of Docker Desktop for Windows which includes a new version.... 19.03.13

Is 19.09 ever coming to Windows too?

greyltc added a commit to greyltc/valheim-server-docker that referenced this pull request Mar 19, 2021
Docker version 19.09 added some new pull logic[1] to the run command that could be used here
[1]: docker/cli#1498
lloesche pushed a commit to lloesche/valheim-server-docker that referenced this pull request Mar 19, 2021
Docker version 19.09 added some new pull logic[1] to the run command that could be used here
[1]: docker/cli#1498
Iristyle added a commit to puppetlabs/pupperware that referenced this pull request Apr 9, 2021
 - docker-compose doesn't automatically pulll latest container
   versions, which can result in unexpectedly old containers
   being used

 - Despite requests for years to add this support to docker-compose
   it hasn't been added. see:

   docker/compose#3574

 - Eventually this will make its way in as part of the work in
   docker/cli#1498
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.