diff --git a/cmd/compose/run.go b/cmd/compose/run.go index 12ee6fbe64e..01fa93f98f7 100644 --- a/cmd/compose/run.go +++ b/cmd/compose/run.go @@ -154,6 +154,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) * options.noTty = !options.tty } } + createOpts.pullChanged = cmd.Flags().Changed("pull") return nil }), RunE: Adapt(func(ctx context.Context, args []string) error { @@ -188,6 +189,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) * flags.StringArrayVarP(&options.publish, "publish", "p", []string{}, "Publish a container's port(s) to the host") flags.BoolVar(&options.useAliases, "use-aliases", false, "Use the service's network useAliases in the network(s) the container connects to") flags.BoolVarP(&options.servicePorts, "service-ports", "P", false, "Run command with all service's ports enabled and mapped to the host") + flags.StringVar(&createOpts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`) flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information") flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container") flags.BoolVar(&options.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") diff --git a/docs/reference/compose_run.md b/docs/reference/compose_run.md index 2d08ef4c4cb..f46d1872d2b 100644 --- a/docs/reference/compose_run.md +++ b/docs/reference/compose_run.md @@ -57,29 +57,30 @@ specified in the service configuration. ### Options -| Name | Type | Default | Description | -|:------------------------|:--------------|:--------|:---------------------------------------------------------------------------------| -| `--build` | `bool` | | Build image before starting container | -| `--cap-add` | `list` | | Add Linux capabilities | -| `--cap-drop` | `list` | | Drop Linux capabilities | -| `-d`, `--detach` | `bool` | | Run container in background and print container ID | -| `--dry-run` | `bool` | | Execute command in dry run mode | -| `--entrypoint` | `string` | | Override the entrypoint of the image | -| `-e`, `--env` | `stringArray` | | Set environment variables | -| `-i`, `--interactive` | `bool` | `true` | Keep STDIN open even if not attached | -| `-l`, `--label` | `stringArray` | | Add or override a label | -| `--name` | `string` | | Assign a name to the container | -| `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation (default: auto-detected) | -| `--no-deps` | `bool` | | Don't start linked services | -| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host | -| `--quiet-pull` | `bool` | | Pull without printing progress information | -| `--remove-orphans` | `bool` | | Remove containers for services not defined in the Compose file | -| `--rm` | `bool` | | Automatically remove the container when it exits | -| `-P`, `--service-ports` | `bool` | | Run command with all service's ports enabled and mapped to the host | -| `--use-aliases` | `bool` | | Use the service's network useAliases in the network(s) the container connects to | -| `-u`, `--user` | `string` | | Run as specified username or uid | -| `-v`, `--volume` | `stringArray` | | Bind mount a volume | -| `-w`, `--workdir` | `string` | | Working directory inside the container | +| Name | Type | Default | Description | +|:------------------------|:--------------|:---------|:---------------------------------------------------------------------------------| +| `--build` | `bool` | | Build image before starting container | +| `--cap-add` | `list` | | Add Linux capabilities | +| `--cap-drop` | `list` | | Drop Linux capabilities | +| `-d`, `--detach` | `bool` | | Run container in background and print container ID | +| `--dry-run` | `bool` | | Execute command in dry run mode | +| `--entrypoint` | `string` | | Override the entrypoint of the image | +| `-e`, `--env` | `stringArray` | | Set environment variables | +| `-i`, `--interactive` | `bool` | `true` | Keep STDIN open even if not attached | +| `-l`, `--label` | `stringArray` | | Add or override a label | +| `--name` | `string` | | Assign a name to the container | +| `-T`, `--no-TTY` | `bool` | `true` | Disable pseudo-TTY allocation (default: auto-detected) | +| `--no-deps` | `bool` | | Don't start linked services | +| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host | +| `--pull` | `string` | `policy` | Pull image before running ("always"\|"missing"\|"never") | +| `--quiet-pull` | `bool` | | Pull without printing progress information | +| `--remove-orphans` | `bool` | | Remove containers for services not defined in the Compose file | +| `--rm` | `bool` | | Automatically remove the container when it exits | +| `-P`, `--service-ports` | `bool` | | Run command with all service's ports enabled and mapped to the host | +| `--use-aliases` | `bool` | | Use the service's network useAliases in the network(s) the container connects to | +| `-u`, `--user` | `string` | | Run as specified username or uid | +| `-v`, `--volume` | `stringArray` | | Bind mount a volume | +| `-w`, `--workdir` | `string` | | Working directory inside the container | diff --git a/docs/reference/docker_compose_run.yaml b/docs/reference/docker_compose_run.yaml index 0584bdd070b..dc19a95de4b 100644 --- a/docs/reference/docker_compose_run.yaml +++ b/docs/reference/docker_compose_run.yaml @@ -180,6 +180,16 @@ options: experimentalcli: false kubernetes: false swarm: false + - option: pull + value_type: string + default_value: policy + description: Pull image before running ("always"|"missing"|"never") + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false - option: quiet-pull value_type: bool default_value: "false" diff --git a/pkg/e2e/compose_run_test.go b/pkg/e2e/compose_run_test.go index 39c2ce0a276..d7e027a0bfc 100644 --- a/pkg/e2e/compose_run_test.go +++ b/pkg/e2e/compose_run_test.go @@ -169,4 +169,14 @@ func TestLocalComposeRun(t *testing.T) { assert.Assert(t, !strings.Contains(res.Combined(), "Pull complete"), res.Combined()) assert.Assert(t, strings.Contains(res.Combined(), "Pulled"), res.Combined()) }) + + t.Run("--pull", func(t *testing.T) { + res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "down", "--rmi", "all") + res.Assert(t, icmd.Success) + + res = c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/pull.yaml", "run", "--pull", "always", "backend") + assert.Assert(t, strings.Contains(res.Combined(), "backend Pulling"), res.Combined()) + assert.Assert(t, strings.Contains(res.Combined(), "Download complete"), res.Combined()) + assert.Assert(t, strings.Contains(res.Combined(), "backend Pulled"), res.Combined()) + }) } diff --git a/pkg/e2e/fixtures/run-test/pull.yaml b/pkg/e2e/fixtures/run-test/pull.yaml new file mode 100644 index 00000000000..223fecd50d7 --- /dev/null +++ b/pkg/e2e/fixtures/run-test/pull.yaml @@ -0,0 +1,4 @@ +services: + backend: + image: nginx + command: nginx -t \ No newline at end of file