Skip to content

Commit 085d8e9

Browse files
authored
Merge pull request docker#9474 from ndeloof/pull_no_pull
introduce --pull
2 parents 70ccc98 + e83d940 commit 085d8e9

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

cmd/compose/create.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
type createOptions struct {
3131
Build bool
3232
noBuild bool
33+
Pull string
3334
removeOrphans bool
3435
ignoreOrphans bool
3536
forceRecreate bool
@@ -56,6 +57,7 @@ func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
5657
return nil
5758
}),
5859
RunE: p.WithProject(func(ctx context.Context, project *types.Project) error {
60+
opts.Apply(project)
5961
return backend.Create(ctx, project, api.CreateOptions{
6062
RemoveOrphans: opts.removeOrphans,
6163
IgnoreOrphans: opts.ignoreOrphans,
@@ -71,6 +73,7 @@ func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
7173
flags := cmd.Flags()
7274
flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.")
7375
flags.BoolVar(&opts.noBuild, "no-build", false, "Don't build an image, even if it's missing.")
76+
flags.StringVar(&opts.Pull, "pull", "missing", `Pull image before running ("always"|"missing"|"never")`)
7477
flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
7578
flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
7679
return cmd
@@ -105,6 +108,12 @@ func (opts createOptions) GetTimeout() *time.Duration {
105108
}
106109

107110
func (opts createOptions) Apply(project *types.Project) {
111+
if opts.Pull != "" {
112+
for i, service := range project.Services {
113+
service.PullPolicy = opts.Pull
114+
project.Services[i] = service
115+
}
116+
}
108117
if opts.Build {
109118
for i, service := range project.Services {
110119
if service.Build == nil {

cmd/compose/up.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func upCommand(p *projectOptions, backend api.Service) *cobra.Command {
115115
flags.BoolVarP(&up.Detach, "detach", "d", false, "Detached mode: Run containers in the background")
116116
flags.BoolVar(&create.Build, "build", false, "Build images before starting containers.")
117117
flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's missing.")
118+
flags.StringVar(&create.Pull, "pull", "missing", `Pull image before running ("always"|"missing"|"never")`)
118119
flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
119120
flags.StringArrayVar(&up.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.")
120121
flags.BoolVar(&up.noColor, "no-color", false, "Produce monochrome output.")

docs/reference/compose_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Creates containers for a service.
1111
| `--force-recreate` | | | Recreate containers even if their configuration and image haven't changed. |
1212
| `--no-build` | | | Don't build an image, even if it's missing. |
1313
| `--no-recreate` | | | If containers already exist, don't recreate them. Incompatible with --force-recreate. |
14+
| `--pull` | `string` | `missing` | Pull image before running ("always"\|"missing"\|"never") |
1415

1516

1617
<!---MARKER_GEN_END-->

docs/reference/compose_up.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Create and start containers
2121
| `--no-log-prefix` | | | Don't print prefix in logs. |
2222
| `--no-recreate` | | | If containers already exist, don't recreate them. Incompatible with --force-recreate. |
2323
| `--no-start` | | | Don't start the services after creating them. |
24+
| `--pull` | `string` | `missing` | Pull image before running ("always"\|"missing"\|"never") |
2425
| `--quiet-pull` | | | Pull without printing progress information. |
2526
| `--remove-orphans` | | | Remove containers for services not defined in the Compose file. |
2627
| `-V`, `--renew-anon-volumes` | | | Recreate anonymous volumes instead of retrieving data from the previous containers. |

docs/reference/docker_compose_create.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ options:
4747
experimentalcli: false
4848
kubernetes: false
4949
swarm: false
50+
- option: pull
51+
value_type: string
52+
default_value: missing
53+
description: Pull image before running ("always"|"missing"|"never")
54+
deprecated: false
55+
hidden: false
56+
experimental: false
57+
experimentalcli: false
58+
kubernetes: false
59+
swarm: false
5060
deprecated: false
5161
experimental: false
5262
experimentalcli: false

docs/reference/docker_compose_up.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ options:
165165
experimentalcli: false
166166
kubernetes: false
167167
swarm: false
168+
- option: pull
169+
value_type: string
170+
default_value: missing
171+
description: Pull image before running ("always"|"missing"|"never")
172+
deprecated: false
173+
hidden: false
174+
experimental: false
175+
experimentalcli: false
176+
kubernetes: false
177+
swarm: false
168178
- option: quiet-pull
169179
value_type: bool
170180
default_value: "false"

0 commit comments

Comments
 (0)