Docker

Pulumi Official
Package maintained by Pulumi
v3.2.0 published on Friday, Apr 1, 2022 by Pulumi

Image

A docker.Image resource represents a Docker image built locally which is published and made available via a remote Docker registry. This can be used to ensure that a Docker source directory from a local deployment environment is built and pushed to a cloud-hosted Docker registry as part of a Pulumi deployment, so that it can be referenced as an image input from other cloud services that reference Docker images - including Kubernetes Pods, AWS ECS Tasks, and Azure Container Instances.

Example Usage

Create And Push Image To Azure Container Registry


using Pulumi;
using Pulumi.Azure.Core;
using Pulumi.Azure.ContainerService;
using Pulumi.Docker;

class MyStack : Stack
{
    private readonly string CustomImage = "my-app";

    public MyStack()
    {
        // Create an Azure Resource Group
        var resourceGroup = new ResourceGroup("resourceGroup");

        var registry = new Registry("myregistry", new RegistryArgs
        {
            AdminEnabled = true,
            Sku = "Basic",
            ResourceGroupName = resourceGroup.Name
        });

        var image = new Image("myimage", new ImageArgs
        {
            ImageName = Output.Format($"{registry.LoginServer}/{CustomImage}:v1.0.0"),
            Build = new DockerBuild
            {
                Context = $"./{CustomImage}"
            },
            Registry = new ImageRegistry { Server = registry.LoginServer, Username = registry.AdminUsername, Password = registry.AdminPassword }
        });
    }
}

package main

import (
	"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/containerservice"
	"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core"
	"github.com/pulumi/pulumi-docker/sdk/v2/go/docker"
	"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Create an Azure Resource Group
		resourceGroup, err := core.NewResourceGroup(ctx, "resourceGroup", &core.ResourceGroupArgs{
			Location: pulumi.String("WestUS"),
		})
		if err != nil {
			return err
		}

		// customImage is a folder containing a Dockerfile.
		customImage := "my-app"
		registry, err := containerservice.NewRegistry(ctx, "myregistry", &containerservice.RegistryArgs{
			AdminEnabled:      pulumi.BoolPtr(true),
			ResourceGroupName: resourceGroup.Name,
			Sku:               pulumi.StringPtr("Basic"),
		})
		if err != nil {
			return err
		}

		_, err = docker.NewImage(ctx, "myimage", &docker.ImageArgs{
			ImageName: pulumi.Sprintf("%s/%s:v1.0.0", registry.LoginServer, customImage),
			Registry: docker.ImageRegistryArgs{
				Server:   registry.LoginServer,
				Username: registry.AdminUsername,
				Password: registry.AdminPassword,
			},
			Build: docker.DockerBuildArgs{
				Context: pulumi.Sprintf("./%s", customImage),
			},
		})
		if err != nil {
			return err
		}

		return nil
	})
}

Coming soon!


import pulumi
from pulumi_azure import core, appservice, containerservice
from pulumi_docker import Image, ImageRegistry, DockerBuild

# The folder containing a Dockerfile.
custom_image = "my-app"

resource_group = core.ResourceGroup('myresourcegroup')

registry = containerservice.Registry(
    "myregistry", admin_enabled="true", resource_group_name=resource_group.name, sku="Basic")

image_registry = pulumi.Output.all(registry.login_server, registry.admin_username, registry.admin_password).apply(
    lambda args: ImageRegistry(args[0], args[1], args[2]))

my_image = Image("myimage",
                 image_name=registry.login_server.apply(
                     lambda server: f'{server}/{custom_image}:v1.0.0'),
                 build=DockerBuild(context=f'./{custom_image}'),
                 registry=image_registry
                 )

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

// The folder containing a Dockerfile.
const customImage = "node-app";

const resourceGroup = new azure.core.ResourceGroup("myresourcegroup");
const registry = new azure.containerservice.Registry("myregistry", {
    resourceGroupName: resourceGroup.name,
    sku: "Basic",
    adminEnabled: true,
});

const myImage = new docker.Image(customImage, {
    imageName: pulumi.interpolate`${registry.loginServer}/${customImage}:v1.0.0`,
    build: {
        context: `./${customImage}`,
    },
    registry: {
        server: registry.loginServer,
        username: registry.adminUsername,
        password: registry.adminPassword,
    },
});

Coming soon!

Create a Image Resource

new Image(name: string, args: ImageArgs, opts?: CustomResourceOptions);
@overload
def Image(image_name,
          build,
          local_image_name=None,
          registry=None,
          skip_push=None,
          opts=None)
@overload
def Image(image_name,
          build,
          local_image_name=None,
          registry=None,
          skip_push=None,
          opts=None)
func NewImage(ctx *Context, name string, args ImageArgs, opts ...ResourceOption) (*Image, error)
public Image(string name, ImageArgs args, CustomResourceOptions? opts = null)
public Image(String name, ImageArgs args)
public Image(String name, ImageArgs args, CustomResourceOptions options)
type: docker:Image
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args ImageArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
image_name
build
local_image_name
registry
skip_push
opts
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args ImageArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args ImageArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args ImageArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Image Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The Image resource accepts the following input properties:

Build string | DockerBuildArgs

The Docker build context, as a folder path or a detailed DockerBuild object.

ImageName string

The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

LocalImageName string

The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

Registry ImageRegistryArgs

Credentials for the docker registry to push to.

SkipPush bool

Skip push flag.

Build string | DockerBuildArgs

The Docker build context, as a folder path or a detailed DockerBuild object.

ImageName string

The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

LocalImageName string

The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

Registry ImageRegistryArgs

Credentials for the docker registry to push to.

SkipPush bool

Skip push flag.

build String | DockerBuildArgs

The Docker build context, as a folder path or a detailed DockerBuild object.

imageName String

The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

localImageName String

The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

registry ImageRegistryArgs

Credentials for the docker registry to push to.

skipPush Boolean

Skip push flag.

build string | DockerBuildArgs

The Docker build context, as a folder path or a detailed DockerBuild object.

imageName string

The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

localImageName string

The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

registry ImageRegistryArgs

Credentials for the docker registry to push to.

skipPush boolean

Skip push flag.

build str | DockerBuildArgs

The Docker build context, as a folder path or a detailed DockerBuild object.

image_name str

The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

local_image_name str

The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

registry ImageRegistryArgs

Credentials for the docker registry to push to.

skip_push bool

Skip push flag.

build String | Property Map

The Docker build context, as a folder path or a detailed DockerBuild object.

imageName String

The qualified image name that will be pushed to the remote registry. Must be a supported image name for the target registry user. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

localImageName String

The docker image name to build locally before tagging with imageName. If not provided, it will be given the value of to [imageName]. This name can include a tag at the end. If provided all pushed image resources will contain that tag as well.

Either [imageName] or [localImageName] can have a tag. However, if both have a tag, then those tags must match.

registry Property Map

Credentials for the docker registry to push to.

skipPush Boolean

Skip push flag.

Outputs

All input properties are implicitly available as output properties. Additionally, the Image resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

BaseImageName string

The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image.

Digest string

It can be used to get a unique name for this specific image, but is not the actual repository digest value.

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

Id string

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

RegistryServer string

The server the image is located at.

Id string

The provider-assigned unique ID for this managed resource.

BaseImageName string

The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image.

Digest string

It can be used to get a unique name for this specific image, but is not the actual repository digest value.

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

Id string

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

RegistryServer string

The server the image is located at.

id String

The provider-assigned unique ID for this managed resource.

baseImageName String

The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image.

digest String

It can be used to get a unique name for this specific image, but is not the actual repository digest value.

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

id String

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

registryServer String

The server the image is located at.

id string

The provider-assigned unique ID for this managed resource.

baseImageName string

The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image.

digest string

It can be used to get a unique name for this specific image, but is not the actual repository digest value.

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

id string

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

registryServer string

The server the image is located at.

id str

The provider-assigned unique ID for this managed resource.

base_image_name str

The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image.

digest str

It can be used to get a unique name for this specific image, but is not the actual repository digest value.

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

id str

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

registry_server str

The server the image is located at.

id String

The provider-assigned unique ID for this managed resource.

baseImageName String

The base image name that was built and pushed. This does not include the id annotation, so is not pinned to the specific build performed by this docker.Image.

digest String

It can be used to get a unique name for this specific image, but is not the actual repository digest value.

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

id String

Deprecated:

This will have the same value as [imageName], but will be removed in the future.

registryServer String

The server the image is located at.

Supporting Types

CacheFrom

Stages List<string>

An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as "[stage-name]".

Stages []string

An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as "[stage-name]".

stages List<String>

An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as "[stage-name]".

stages string[]

An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as "[stage-name]".

stages Sequence[str]

An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as "[stage-name]".

stages List<String>

An optional list of build stages to use for caching. Each build stage in this list will be built explicitly and pushed to the target repository. A given stage’s image will be tagged as "[stage-name]".

DockerBuild

Args Dictionary<string, string>

An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the RUN instruction.

CacheFrom bool | CacheFrom
Context string

context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.

Dockerfile string

dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.

Env Dictionary<string, string>

Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.

ExtraOptions List<string>

An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify --network host.

Target string

The target of the dockerfile to build

Args map[string]string

An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the RUN instruction.

CacheFrom bool | CacheFrom
Context string

context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.

Dockerfile string

dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.

Env map[string]string

Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.

ExtraOptions []string

An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify --network host.

Target string

The target of the dockerfile to build

args Map<String,String>

An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the RUN instruction.

cacheFrom Boolean | CacheFrom
context String

context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.

dockerfile String

dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.

env Map<String,String>

Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.

extraOptions List<String>

An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify --network host.

target String

The target of the dockerfile to build

args {[key: string]: string}

An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the RUN instruction.

cacheFrom boolean | CacheFrom
context string

context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.

dockerfile string

dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.

env {[key: string]: string}

Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.

extraOptions string[]

An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify --network host.

target string

The target of the dockerfile to build

args Mapping[str, str]

An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the RUN instruction.

cache_from bool | CacheFrom
context str

context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.

dockerfile str

dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.

env Mapping[str, str]

Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.

extra_options Sequence[str]

An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify --network host.

target str

The target of the dockerfile to build

args Map<String>

An optional map of named build-time argument variables to set during the Docker build. This flag allows you to pass built-time variables that can be accessed like environment variables inside the RUN instruction.

cacheFrom Boolean | Property Map
context String

context is a path to a directory to use for the Docker build context, usually the directory in which the Dockerfile resides (although dockerfile may be used to choose a custom location independent of this choice). If not specified, the context defaults to the current working directory; if a relative path is used, it is relative to the current working directory that Pulumi is evaluating.

dockerfile String

dockerfile may be used to override the default Dockerfile name and/or location. By default, it is assumed to be a file named Dockerfile in the root of the build context.

env Map<String>

Environment variables to set on the invocation of docker build, for example to support DOCKER_BUILDKIT=1 docker build.

extraOptions List<String>

An optional catch-all string to provide extra CLI options to the docker build command. For example, use to specify --network host.

target String

The target of the dockerfile to build

ImageRegistry

Password string

Password for login to the target Docker registry.

Server string

Docker registry server URL to push to. Some common values include: DockerHub: docker.io or https://index.docker.io/v1 Azure Container Registry: <name>.azurecr.io AWS Elastic Container Registry: <account>.dkr.ecr.us-east-2.amazonaws.com Google Container Registry: <name>.gcr.io.

Username string

Username for login to the target Docker registry.

Password string

Password for login to the target Docker registry.

Server string

Docker registry server URL to push to. Some common values include: DockerHub: docker.io or https://index.docker.io/v1 Azure Container Registry: <name>.azurecr.io AWS Elastic Container Registry: <account>.dkr.ecr.us-east-2.amazonaws.com Google Container Registry: <name>.gcr.io.

Username string

Username for login to the target Docker registry.

password String

Password for login to the target Docker registry.

server String

Docker registry server URL to push to. Some common values include: DockerHub: docker.io or https://index.docker.io/v1 Azure Container Registry: <name>.azurecr.io AWS Elastic Container Registry: <account>.dkr.ecr.us-east-2.amazonaws.com Google Container Registry: <name>.gcr.io.

username String

Username for login to the target Docker registry.

password string

Password for login to the target Docker registry.

server string

Docker registry server URL to push to. Some common values include: DockerHub: docker.io or https://index.docker.io/v1 Azure Container Registry: <name>.azurecr.io AWS Elastic Container Registry: <account>.dkr.ecr.us-east-2.amazonaws.com Google Container Registry: <name>.gcr.io.

username string

Username for login to the target Docker registry.

password str

Password for login to the target Docker registry.

server str

Docker registry server URL to push to. Some common values include: DockerHub: docker.io or https://index.docker.io/v1 Azure Container Registry: <name>.azurecr.io AWS Elastic Container Registry: <account>.dkr.ecr.us-east-2.amazonaws.com Google Container Registry: <name>.gcr.io.

username str

Username for login to the target Docker registry.

password String

Password for login to the target Docker registry.

server String

Docker registry server URL to push to. Some common values include: DockerHub: docker.io or https://index.docker.io/v1 Azure Container Registry: <name>.azurecr.io AWS Elastic Container Registry: <account>.dkr.ecr.us-east-2.amazonaws.com Google Container Registry: <name>.gcr.io.

username String

Username for login to the target Docker registry.

Package Details

Repository
https://github.com/pulumi/pulumi-docker
License
Apache-2.0
Notes

This Pulumi package is based on the docker Terraform Provider.