Skip to content

Commit 34bcd03

Browse files
gloursndeloof
authored andcommitted
add --pull to run command
Signed-off-by: Guillaume Lours <[email protected]>
1 parent ed61e42 commit 34bcd03

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

cmd/compose/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
154154
options.noTty = !options.tty
155155
}
156156
}
157+
createOpts.pullChanged = cmd.Flags().Changed("pull")
157158
return nil
158159
}),
159160
RunE: Adapt(func(ctx context.Context, args []string) error {
@@ -188,6 +189,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
188189
flags.StringArrayVarP(&options.publish, "publish", "p", []string{}, "Publish a container's port(s) to the host")
189190
flags.BoolVar(&options.useAliases, "use-aliases", false, "Use the service's network useAliases in the network(s) the container connects to")
190191
flags.BoolVarP(&options.servicePorts, "service-ports", "P", false, "Run command with all service's ports enabled and mapped to the host")
192+
flags.StringVar(&createOpts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`)
191193
flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information")
192194
flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container")
193195
flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file")

docs/reference/compose_run.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,30 @@ specified in the service configuration.
5757

5858
### Options
5959

60-
| Name | Type | Default | Description |
61-
|:------------------------|:--------------|:--------|:---------------------------------------------------------------------------------|
62-
| `--build` | `bool` | | Build image before starting container |
63-
| `--cap-add` | `list` | | Add Linux capabilities |
64-
| `--cap-drop` | `list` | | Drop Linux capabilities |
65-
| `-d`, `--detach` | `bool` | | Run container in background and print container ID |
66-
| `--dry-run` | `bool` | | Execute command in dry run mode |
67-
| `--entrypoint` | `string` | | Override the entrypoint of the image |
68-
| `-e`, `--env` | `stringArray` | | Set environment variables |
69-
| `-i`, `--interactive` | `bool` | `true` | Keep STDIN open even if not attached |
70-
| `-l`, `--label` | `stringArray` | | Add or override a label |
71-
| `--name` | `string` | | Assign a name to the container |
72-
| `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation (default: auto-detected) |
73-
| `--no-deps` | `bool` | | Don't start linked services |
74-
| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host |
75-
| `--quiet-pull` | `bool` | | Pull without printing progress information |
76-
| `--remove-orphans` | `bool` | | Remove containers for services not defined in the Compose file |
77-
| `--rm` | `bool` | | Automatically remove the container when it exits |
78-
| `-P`, `--service-ports` | `bool` | | Run command with all service's ports enabled and mapped to the host |
79-
| `--use-aliases` | `bool` | | Use the service's network useAliases in the network(s) the container connects to |
80-
| `-u`, `--user` | `string` | | Run as specified username or uid |
81-
| `-v`, `--volume` | `stringArray` | | Bind mount a volume |
82-
| `-w`, `--workdir` | `string` | | Working directory inside the container |
60+
| Name | Type | Default | Description |
61+
|:------------------------|:--------------|:---------|:---------------------------------------------------------------------------------|
62+
| `--build` | `bool` | | Build image before starting container |
63+
| `--cap-add` | `list` | | Add Linux capabilities |
64+
| `--cap-drop` | `list` | | Drop Linux capabilities |
65+
| `-d`, `--detach` | `bool` | | Run container in background and print container ID |
66+
| `--dry-run` | `bool` | | Execute command in dry run mode |
67+
| `--entrypoint` | `string` | | Override the entrypoint of the image |
68+
| `-e`, `--env` | `stringArray` | | Set environment variables |
69+
| `-i`, `--interactive` | `bool` | `true` | Keep STDIN open even if not attached |
70+
| `-l`, `--label` | `stringArray` | | Add or override a label |
71+
| `--name` | `string` | | Assign a name to the container |
72+
| `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation (default: auto-detected) |
73+
| `--no-deps` | `bool` | | Don't start linked services |
74+
| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host |
75+
| `--pull` | `string` | `policy` | Pull image before running ("always"\|"missing"\|"never") |
76+
| `--quiet-pull` | `bool` | | Pull without printing progress information |
77+
| `--remove-orphans` | `bool` | | Remove containers for services not defined in the Compose file |
78+
| `--rm` | `bool` | | Automatically remove the container when it exits |
79+
| `-P`, `--service-ports` | `bool` | | Run command with all service's ports enabled and mapped to the host |
80+
| `--use-aliases` | `bool` | | Use the service's network useAliases in the network(s) the container connects to |
81+
| `-u`, `--user` | `string` | | Run as specified username or uid |
82+
| `-v`, `--volume` | `stringArray` | | Bind mount a volume |
83+
| `-w`, `--workdir` | `string` | | Working directory inside the container |
8384

8485

8586
<!---MARKER_GEN_END-->

docs/reference/docker_compose_run.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ options:
180180
experimentalcli: false
181181
kubernetes: false
182182
swarm: false
183+
- option: pull
184+
value_type: string
185+
default_value: policy
186+
description: Pull image before running ("always"|"missing"|"never")
187+
deprecated: false
188+
hidden: false
189+
experimental: false
190+
experimentalcli: false
191+
kubernetes: false
192+
swarm: false
183193
- option: quiet-pull
184194
value_type: bool
185195
default_value: "false"

pkg/e2e/compose_run_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,14 @@ func TestLocalComposeRun(t *testing.T) {
169169
assert.Assert(t, !strings.Contains(res.Combined(), "Pull complete"), res.Combined())
170170
assert.Assert(t, strings.Contains(res.Combined(), "Pulled"), res.Combined())
171171
})
172+
173+
t.Run("--pull", func(t *testing.T) {
174+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "down", "--rmi", "all")
175+
res.Assert(t, icmd.Success)
176+
177+
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "run", "--pull", "always", "backend")
178+
assert.Assert(t, strings.Contains(res.Combined(), "backend Pulling"), res.Combined())
179+
assert.Assert(t, strings.Contains(res.Combined(), "Download complete"), res.Combined())
180+
assert.Assert(t, strings.Contains(res.Combined(), "backend Pulled"), res.Combined())
181+
})
172182
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
backend:
3+
image: nginx
4+
command: nginx -t

0 commit comments

Comments
 (0)