Pulumi Docker
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
- breaking Breaking change in `v4.7.0`: The `RemoteImageBuild` resource's `buildArg` property was removed. Programs using this property will fail upon upgrade.
- breaking Significant overhaul of the `docker.Image` resource in `v4.0.0`. This included breaking changes to its behavior, supporting types, and minor name changes. Existing programs using `docker.Image` might require code adjustments.
- gotcha When configuring `registryAuth` for the Docker provider, passing `config_file` (e.g., `~/.docker/config.json`) may trigger a type checking warning (as of v4.6.1) that indicates it will become a hard error. This is a discrepancy between documentation and type definitions.
- gotcha When using `pulumi-docker` with a remote Docker host, the remote daemon's default configuration might apply settings (e.g., log options) that are not explicitly defined in your Pulumi program. This can cause spurious diffs during `pulumi preview` or `pulumi up` on subsequent runs.
- gotcha `docker build` operations within Pulumi programs, especially when using `cacheFrom: true` or specific credential helpers (like for Google Container Registry), can significantly slow down `pulumi preview` and `pulumi up`, even if all layers are cached locally.
- gotcha While `pulumi-docker` supports building images, for production environments and complex applications, it's often recommended to separate concerns by using dedicated CI/CD pipelines for building and pushing Docker images. Pulumi should then consume these pre-built images from a container registry.
Install
-
pip install pulumi-docker
Imports
- docker
import pulumi_docker as docker
- RemoteImage
from pulumi_docker import RemoteImage
- Container
from pulumi_docker import Container
Quickstart
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)