Skip to main content

docker.create.execute

Create a new container from a specified image.

Usage

task := plan.TaskFunc("create-container",
func(ctx context.Context, c *client.Client) (*orchestrator.Result, error) {
autoStart := true
resp, err := c.Docker.Create(ctx, "_any", gen.DockerCreateRequest{
Image: "nginx:alpine",
Name: ptr("my-nginx"),
AutoStart: &autoStart,
})
if err != nil {
return nil, err
}
r := resp.Data.Results[0]
return &orchestrator.Result{
Changed: true,
Data: map[string]any{"id": r.ID, "name": r.Name},
}, nil
},
)

Parameters

ParamTypeRequiredDescription
imagestringYesContainer image reference
namestringNoOptional container name
env[]stringNoEnvironment variables (KEY=VALUE)
ports[]stringNoPort mappings (host:container)
volumes[]stringNoVolume mounts (host:container)
auto_startboolNoStart immediately after creation (true)

Target

Accepts any valid target: _any, _all, a hostname, or a label selector (key:value).

Idempotency

Not idempotent. Always creates a new container. Use guards to prevent duplicate creation.

Permissions

Requires docker:write permission.

Example

See examples/sdk/orchestrator/features/container-targeting.go for a complete working example.