mirror of
https://github.com/docker/compose.git
synced 2026-08-30 05:29:30 +00:00
Merge pull request #988 from docker/feat-platform
Add platform when running containers
This commit is contained in:
commit
4270f383a7
11 changed files with 153 additions and 100 deletions
|
|
@ -67,6 +67,10 @@ func Command(contextType string) *cobra.Command {
|
|||
"health-retries countdown (ms|s|m|h) (default 0s)")
|
||||
cmd.Flags().DurationVar(&opts.HealthTimeout, "health-timeout", time.Duration(0), "Maximum time to allow one check to run (ms|s|m|h) (default 0s)")
|
||||
|
||||
if contextType == store.LocalContextType {
|
||||
cmd.Flags().StringVar(&opts.Platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
|
||||
}
|
||||
|
||||
if contextType == store.AciContextType {
|
||||
cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/docker/pkg/namesgenerator"
|
||||
"github.com/docker/go-connections/nat"
|
||||
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
||||
"github.com/docker/compose-cli/api/containers"
|
||||
"github.com/docker/compose-cli/formatter"
|
||||
|
|
@ -51,6 +53,7 @@ type Opts struct {
|
|||
HealthRetries int
|
||||
HealthStartPeriod time.Duration
|
||||
HealthTimeout time.Duration
|
||||
Platform string
|
||||
}
|
||||
|
||||
// RestartPolicyList all available restart policy values
|
||||
|
|
@ -86,6 +89,16 @@ func (r *Opts) ToContainerConfig(image string) (containers.ContainerConfig, erro
|
|||
envVars = append(envVars, vars...)
|
||||
}
|
||||
|
||||
var platform *specs.Platform
|
||||
|
||||
if r.Platform != "" {
|
||||
p, err := platforms.Parse(r.Platform)
|
||||
if err != nil {
|
||||
return containers.ContainerConfig{}, err
|
||||
}
|
||||
platform = &p
|
||||
}
|
||||
|
||||
return containers.ContainerConfig{
|
||||
ID: r.Name,
|
||||
Image: image,
|
||||
|
|
@ -100,6 +113,7 @@ func (r *Opts) ToContainerConfig(image string) (containers.ContainerConfig, erro
|
|||
DomainName: r.DomainName,
|
||||
AutoRemove: r.Rm,
|
||||
Healthcheck: r.toHealthcheck(),
|
||||
Platform: platform,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue