Pulumi Docker

4.11.2 · active · verified Wed Apr 15

Pulumi Docker is a Pulumi package for interacting with Docker in Pulumi programs, allowing users to define, deploy, and manage Docker containers, images, networks, and volumes using general-purpose programming languages. It is currently at version 4.11.2 and maintains an active release cadence with frequent minor updates, often incorporating bridge upgrades and GitHub Actions workflow improvements.

Warnings

Install

Imports

Quickstart

This quickstart program pulls the `nginx:latest` Docker image and then creates a container, exposing port 8080 on the host mapped to port 80 internally in the container. It then exports the container ID and the external port. For private registries, uncomment and configure the `registry` arguments within `RemoteImage` using environment variables for sensitive credentials.

import pulumi
import pulumi_docker as docker
import os

# Pull a remote Docker image (e.g., NGINX latest)
nginx_image = docker.RemoteImage("nginx-image",
    name="nginx:latest"
)

# Create a Docker container from the pulled image
nginx_container = docker.Container("nginx-container",
    image=nginx_image.image_id,
    ports=[docker.ContainerPortArgs(
        internal=80,
        external=8080,
    )],
    # Example of setting environment variables for a private registry if needed
    # registry=docker.RegistryArgs(
    #     server="your.private.registry",
    #     username=os.environ.get('DOCKER_REGISTRY_USER', ''),
    #     password=os.environ.get('DOCKER_REGISTRY_PASS', ''),
    # )
)

# Export the container ID and the external port
pulumi.export("container_id", nginx_container.id)
pulumi.export("external_port", 8080)

view raw JSON →