Container class

<!-- Bug: Type and Name are switched --> Manages the lifecycle of a Docker container.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";

// Find the latest Ubuntu precise image.
const ubuntuRemoteImage = new docker.RemoteImage("ubuntu", {name: "ubuntu:precise"});
// Start a container
const ubuntu = new docker.Container("ubuntu", {
    name: "foo",
    image: ubuntuRemoteImage.imageId,
});
import pulumi
import pulumi_docker as docker

# Find the latest Ubuntu precise image.
ubuntu_remote_image = docker.RemoteImage("ubuntu", name="ubuntu:precise")
# Start a container
ubuntu = docker.Container("ubuntu",
    name="foo",
    image=ubuntu_remote_image.image_id)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Docker = Pulumi.Docker;

return await Deployment.RunAsync(() =>
{
    // Find the latest Ubuntu precise image.
    var ubuntuRemoteImage = new Docker.RemoteImage("ubuntu", new()
    {
        Name = "ubuntu:precise",
    });

    // Start a container
    var ubuntu = new Docker.Container("ubuntu", new()
    {
        Name = "foo",
        Image = ubuntuRemoteImage.ImageId,
    });

});
package main

import (
	"github.com/pulumi/pulumi-docker/sdk/v5/go/docker"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Find the latest Ubuntu precise image.
		ubuntuRemoteImage, err := docker.NewRemoteImage(ctx, "ubuntu", &docker.RemoteImageArgs{
			Name: pulumi.String("ubuntu:precise"),
		})
		if err != nil {
			return err
		}
		// Start a container
		_, err = docker.NewContainer(ctx, "ubuntu", &docker.ContainerArgs{
			Name:  pulumi.String("foo"),
			Image: ubuntuRemoteImage.ImageId,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    docker = {
      source = "pulumi/docker"
    }
  }
}

# Start a container
resource "docker_container" "ubuntu" {
  name  = "foo"
  image = docker_remoteimage.ubuntu.image_id
}
# Find the latest Ubuntu precise image.
resource "docker_remoteimage" "ubuntu" {
  name = "ubuntu:precise"
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.docker.RemoteImage;
import com.pulumi.docker.RemoteImageArgs;
import com.pulumi.docker.Container;
import com.pulumi.docker.ContainerArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        // Find the latest Ubuntu precise image.
        var ubuntuRemoteImage = new RemoteImage("ubuntuRemoteImage", RemoteImageArgs.builder()
            .name("ubuntu:precise")
            .build());

        // Start a container
        var ubuntu = new Container("ubuntu", ContainerArgs.builder()
            .name("foo")
            .image(ubuntuRemoteImage.imageId())
            .build());

    }
}
resources:
  # Start a container
  ubuntu:
    type: docker:Container
    properties:
      name: foo
      image: ${ubuntuRemoteImage.imageId}
  # Find the latest Ubuntu precise image.
  ubuntuRemoteImage:
    type: docker:RemoteImage
    name: ubuntu
    properties:
      name: ubuntu:precise

Import

!/bin/bash

$ pulumi import docker:index/container:Container foo id

Example

Assuming you created a container as follows

#!/bin/bash
docker run --name foo -p8080:80 -d nginx
# prints the container ID
9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd

you provide the definition for the resource as follows

import * as pulumi from "@pulumi/pulumi";
import * as docker from "@pulumi/docker";

const foo = new docker.Container("foo", {
    name: "foo",
    image: "nginx",
    ports: [{
        internal: 80,
        external: 8080,
    }],
});
import pulumi
import pulumi_docker as docker

foo = docker.Container("foo",
    name="foo",
    image="nginx",
    ports=[{
        "internal": 80,
        "external": 8080,
    }])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Docker = Pulumi.Docker;

return await Deployment.RunAsync(() =>
{
    var foo = new Docker.Container("foo", new()
    {
        Name = "foo",
        Image = "nginx",
        Ports = new[]
        {
            new Docker.Inputs.ContainerPortArgs
            {
                Internal = 80,
                External = 8080,
            },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-docker/sdk/v5/go/docker"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := docker.NewContainer(ctx, "foo", &docker.ContainerArgs{
			Name:  pulumi.String("foo"),
			Image: pulumi.String("nginx"),
			Ports: docker.ContainerPortArray{
				&docker.ContainerPortArgs{
					Internal: pulumi.Int(80),
					External: pulumi.Int(8080),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    docker = {
      source = "pulumi/docker"
    }
  }
}

resource "docker_container" "foo" {
  name  = "foo"
  image = "nginx"
  ports {
    internal = "80"
    external = "8080"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.docker.Container;
import com.pulumi.docker.ContainerArgs;
import com.pulumi.docker.inputs.ContainerPortArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var foo = new Container("foo", ContainerArgs.builder()
            .name("foo")
            .image("nginx")
            .ports(ContainerPortArgs.builder()
                .internal(80)
                .external(8080)
                .build())
            .build());

    }
}
resources:
  foo:
    type: docker:Container
    properties:
      name: foo
      image: nginx
      ports:
        - internal: '80'
          external: '8080'

then the import command is as follows

!/bin/bash

$ pulumi import docker:index/container:Container foo 9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd

Constructors

Container(String name, {ContainerArgs? args, CustomResourceOptions? options})
Creates a new Container. name The Pulumi resource name. args Arguments used to configure this Container. The set of arguments for Container. options Resource options controlling this resource's behavior.
Container.reference(String urn)
Creates a typed reference to an existing Container resource.

Properties

attach ↔ Output<bool?>
If true attach to the container after its creation and waits the end of its execution. Defaults to false.
latefinal
bridge ↔ Output<String>
The network bridge of the container as read from its NetworkSettings.
latefinal
capabilities ↔ Output<ContainerCapabilities?>
Add or drop certain linux capabilities.
latefinal
cgroupnsMode ↔ Output<String?>
Cgroup namespace mode to use for the container. Possible values are: private, host.
latefinal
cgroupParent ↔ Output<String?>
Optional parent cgroup for the container
latefinal
childResources → Set<Resource>
finalinherited
command ↔ Output<List<String>>
The command to use to start the container. For example, to run /usr/bin/myprogram -f baz.conf set the command to be ["/usr/bin/myprogram","-f","baz.conf"].
latefinal
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
containerLogs ↔ Output<String>
The logs of the container if its execution is done (attach must be disabled).
latefinal
containerReadRefreshTimeoutMilliseconds ↔ Output<int?>
The total number of milliseconds to wait for the container to reach status 'running'
latefinal
cpuPeriod ↔ Output<int?>
Specify the CPU CFS scheduler period (in microseconds), which is used alongside cpu-quota. Is ignored if cpus is set.
latefinal
cpuQuota ↔ Output<int?>
Impose a CPU CFS quota on the container (in microseconds). The number of microseconds per cpu-period that the container is limited to before throttled. Is ignored if cpus is set.
latefinal
cpus ↔ Output<String?>
Specify how much of the available CPU resources a container can use. e.g a value of 1.5 means the container is guaranteed at most one and a half of the CPUs. Has precedence over cpuPeriod and cpuQuota.
latefinal
cpuSet ↔ Output<String?>
A comma-separated list or hyphen-separated range of CPUs a container can use, e.g. 0-1.
latefinal
cpuShares ↔ Output<int?>
CPU shares (relative weight) for the container.
latefinal
destroyGraceSeconds ↔ Output<int?>
If defined will attempt to stop the container before destroying. Container will be destroyed after n seconds or on successful stop.
latefinal
deviceCgroupRules ↔ Output<List<String>?>
Cgroup rules to allow access to classes of devices without binding specific device nodes.
latefinal
deviceReadBps ↔ Output<List<ContainerDeviceReadBp>?>
Limit read rate (bytes per second) from a device. This is the equivalent to repeating --device-read-bps for docker run.
latefinal
deviceReadIops ↔ Output<List<ContainerDeviceReadIop>?>
Limit read rate (IO per second) from a device. This is the equivalent to repeating --device-read-iops for docker run.
latefinal
deviceRequests ↔ Output<List<ContainerDeviceRequest>?>
Device requests for the container, such as CDI devices (e.g., nvidia.com/gpu=all) or GPU requests. This is the equivalent to using the --device flag for CDI devices in docker run.
latefinal
devices ↔ Output<List<ContainerDevice>?>
Bind traditional devices to the container (e.g., /dev/nvidia0). For CDI devices, use deviceRequests instead.
latefinal
deviceWriteBps ↔ Output<List<ContainerDeviceWriteBp>?>
Limit write rate (bytes per second) to a device. This is the equivalent to repeating --device-write-bps for docker run.
latefinal
deviceWriteIops ↔ Output<List<ContainerDeviceWriteIop>?>
Limit write rate (IO per second) to a device. This is the equivalent to repeating --device-write-iops for docker run.
latefinal
dns ↔ Output<List<String>?>
DNS servers to use.
latefinal
dnsOpts ↔ Output<List<String>?>
DNS options used by the DNS provider(s), see resolv.conf documentation for valid list of options.
latefinal
dnsSearches ↔ Output<List<String>?>
DNS search domains that are used when bare unqualified hostnames are used inside of the container.
latefinal
domainname ↔ Output<String?>
Domain name of the container.
latefinal
entrypoints ↔ Output<List<String>>
The command to use as the Entrypoint for the container. The Entrypoint allows you to configure a container to run as an executable. For example, to run /usr/bin/myprogram when starting a container, set the entrypoint to be "/usr/bin/myprogram"].
latefinal
envs ↔ Output<List<String>>
Environment variables to set in the form of KEY=VALUE, e.g. DEBUG=0
latefinal
exitCode ↔ Output<int>
The exit code of the container if its execution is done (mustRun must be disabled).
latefinal
gpus ↔ Output<String?>
GPU devices to add to the container. Supported values are all or device=&lt;id[,id...]&gt;, for example device=0,2 or device=GPU-3a23c669-1f69-c64e-cf85-44e9b07e7a2a.
latefinal
groupAdds ↔ Output<List<String>?>
Additional groups for the container user
latefinal
hashCode → int
The hash code for this object.
no setterinherited
healthcheck ↔ Output<ContainerHealthcheck>
A test to perform to check that the container is healthy
latefinal
hostname ↔ Output<String>
Hostname of the container.
latefinal
hosts ↔ Output<List<ContainerHost>?>
Additional hosts to add to the container.
latefinal
id ↔ Output<String>
getter/setter pairinherited
image ↔ Output<String>
The ID of the image to back this container. The easiest way to get this value is to use the imageId attribute of the docker.RemoteImage resource as is shown in the example.
latefinal
init ↔ Output<bool>
Configured whether an init process should be injected for this container. If unset this will default to the dockerd defaults.
latefinal
ipcMode ↔ Output<String>
IPC sharing mode for the container. Possible values are: none, private, shareable, container:&lt;name|id&gt; or host.
latefinal
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
labels ↔ Output<List<ContainerLabel>>
User-defined key/value metadata
latefinal
logDriver ↔ Output<String>
The logging driver to use for the container.
latefinal
logOpts ↔ Output<Map<String, String>?>
Key/value pairs to use as options for the logging driver.
latefinal
logs ↔ Output<bool?>
Save the container logs (attach must be enabled). Defaults to false.
latefinal
maxRetryCount ↔ Output<int?>
The maximum amount of times to an attempt a restart when restart is set to 'on-failure'.
latefinal
memory ↔ Output<int?>
The memory limit for the container in MBs.
latefinal
memoryReservation ↔ Output<int?>
The memory-resveration for the container in MBs. Defaults to 0. Allows you to specify a soft limit smaller than memory which is activated when Docker detects contention or low memory on the host machine. If you use memory-reservation, it must be set lower than memory for it to take precedence. Because it is a soft limit, it doesn't guarantee that the container doesn't exceed the limit.
latefinal
memorySwap ↔ Output<int?>
The total memory limit (memory + swap) for the container in MBs. This setting may compute to -1 after pulumi up if the target host doesn't support memory swap, when that is the case docker will use a soft limitation.
latefinal
mounts ↔ Output<List<ContainerMount>?>
Specification for mounts to be added to containers created as part of the service.
latefinal
mustRun ↔ Output<bool?>
If true, then the Docker container will be kept running. If false, Terraform leaves the container alone. This attribute is also used to trigger a restart of a stopped container. If your container is stopped, Terraform will set mustRun to false and this will trigger a change. Defaults to true.
latefinal
name ↔ Output<String>
The name of the container.
latefinal
networkDatas ↔ Output<List<ContainerNetworkData>>
The data of the networks the container is connected to.
latefinal
networkMode ↔ Output<String?>
Network mode of the container. Defaults to bridge. If your host OS is any other OS, you need to set this value explicitly, e.g. nat when your container will be running on an Windows host. See https://docs.docker.com/engine/network/ for more information.
latefinal
networksAdvanced ↔ Output<List<ContainerNetworksAdvanced>?>
The networks the container is attached to. This is the equivalent to the --network option of docker run
latefinal
pidMode ↔ Output<String?>
The PID (Process) Namespace mode for the container. Either container:&lt;name|id&gt; or host.
latefinal
platform ↔ Output<String>
Platform in the format os[/arch[/variant]] used for image lookup and container runtime, for example linux/amd64.
latefinal
ports ↔ Output<List<ContainerPort>?>
Publish a container's port(s) to the host.
latefinal
privileged ↔ Output<bool?>
If true, the container runs in privileged mode.
latefinal
publishAllPorts ↔ Output<bool?>
Publish all ports of the container.
latefinal
readOnly ↔ Output<bool?>
If true, the container will be started as readonly. Defaults to false.
latefinal
removeVolumes ↔ Output<bool?>
If true, it will remove anonymous volumes associated with the container. Defaults to true.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
restart ↔ Output<String?>
The restart policy for the container. Must be one of 'no', 'on-failure', 'always', 'unless-stopped'. Defaults to no.
latefinal
rm ↔ Output<bool?>
If true, then the container will be automatically removed when it exits. Defaults to false.
latefinal
runtime ↔ Output<String>
Runtime to use for the container.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
securityOpts ↔ Output<List<String>>
List of string values to customize labels for MLS systems, such as SELinux. See https://docs.docker.com/engine/reference/run/#security-configuration.
latefinal
shmSize ↔ Output<int>
Size of /dev/shm in MBs.
latefinal
start ↔ Output<bool?>
If true, then the Docker container will be started after creation. If false, then the container is only created. Defaults to true.
latefinal
stdinOpen ↔ Output<bool?>
If true, keep STDIN open even if not attached (docker run -i). Defaults to false.
latefinal
stopSignal ↔ Output<String>
Signal to stop a container (default SIGTERM).
latefinal
stopTimeout ↔ Output<int>
Timeout (in seconds) to stop a container.
latefinal
storageOpts ↔ Output<Map<String, String>?>
Key/value pairs for the storage driver options, e.g. size: 120G
latefinal
sysctls ↔ Output<Map<String, String>?>
A map of kernel parameters (sysctls) to set in the container.
latefinal
tmpfs ↔ Output<Map<String, String>?>
A map of container directories which should be replaced by tmpfs mounts, and their corresponding mount options.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
tty ↔ Output<bool?>
If true, allocate a pseudo-tty (docker run -t). Defaults to false.
latefinal
ulimits ↔ Output<List<ContainerUlimit>?>
Ulimit options to add.
latefinal
uploads ↔ Output<List<ContainerUpload>?>
Specifies files to upload to the container before starting it. Only one of content or contentBase64 can be set and at least one of them has to be set.
latefinal
urn ↔ Output<String>
latefinalinherited
user ↔ Output<String?>
User used for run the first process. Format is user or user:group which user and group can be passed literally or by name.
latefinal
usernsMode ↔ Output<String?>
Sets the usernamespace mode for the container when usernamespace remapping option is enabled.
latefinal
volumes ↔ Output<List<ContainerVolume>?>
Spec for mounting volumes in the container.
latefinal
wait ↔ Output<bool?>
If true, then the Docker container is waited for being healthy state after creation. This requires your container to have a healthcheck, otherwise this provider will error. If false, then the container health state is not checked. Defaults to false.
latefinal
waitTimeout ↔ Output<int?>
The timeout in seconds to wait the container to be healthy after creation. Defaults to 60.
latefinal
workingDir ↔ Output<String?>
The working directory for commands to run in.
latefinal

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {ContainerState? state, CustomResourceOptions? options}) → Container
Gets an existing Container resource's state with the given name and id.