What is @pulumi/docker?
@pulumi/docker is an npm package that allows you to manage Docker resources using Pulumi, a modern infrastructure as code platform. With this package, you can define, deploy, and manage Docker containers, images, and networks programmatically using JavaScript, TypeScript, or other supported languages.
What are @pulumi/docker's main functionalities?
Building Docker Images
This feature allows you to build Docker images from a specified directory. The code sample demonstrates how to build an image from the './app' directory and tag it as 'my-repo/my-image:latest'.
const pulumi = require('@pulumi/pulumi');
const docker = require('@pulumi/docker');
const image = new docker.Image('my-image', {
build: './app',
imageName: 'my-repo/my-image:latest',
});
exports.imageName = image.imageName;
Running Docker Containers
This feature allows you to run Docker containers. The code sample demonstrates how to run a container from the 'my-repo/my-image:latest' image and map port 80 inside the container to port 8080 on the host.
const pulumi = require('@pulumi/pulumi');
const docker = require('@pulumi/docker');
const container = new docker.Container('my-container', {
image: 'my-repo/my-image:latest',
ports: [{ internal: 80, external: 8080 }],
});
exports.containerId = container.id;
Managing Docker Networks
This feature allows you to create and manage Docker networks. The code sample demonstrates how to create a custom Docker network named 'my-custom-network'.
const pulumi = require('@pulumi/pulumi');
const docker = require('@pulumi/docker');
const network = new docker.Network('my-network', {
name: 'my-custom-network',
});
exports.networkName = network.name;
Other packages similar to @pulumi/docker
dockerode
dockerode is a Docker client for Node.js that allows you to interact with the Docker Remote API. It provides a more direct and lower-level interface to Docker compared to @pulumi/docker, which is more focused on infrastructure as code and higher-level abstractions.
node-docker-api
node-docker-api is another Node.js client for the Docker Remote API. Similar to dockerode, it provides a low-level interface to Docker, allowing you to manage containers, images, networks, and more. It is less focused on infrastructure as code compared to @pulumi/docker.
docker-cli-js
docker-cli-js is a Node.js module that allows you to interact with Docker using the command line interface (CLI). It provides a way to run Docker commands from within a Node.js application. Unlike @pulumi/docker, it does not provide a high-level infrastructure as code approach.
Docker Resource Provider
The Docker resource provider for Pulumi lets you manage Docker resources in your cloud programs. To use
this package, please install the Pulumi CLI first.
Installing
This package is available in many languages in the standard packaging formats.
Node.js (Java/TypeScript)
To use from JavaScript or TypeScript in Node.js, install using either npm
:
$ npm install @pulumi/docker
or yarn
:
$ yarn add @pulumi/docker
Python
To use from Python, install using pip
:
$ pip install pulumi_docker
Go
To use from Go, use go get
to grab the latest version of the library
$ go get github.com/pulumi/pulumi-docker/sdk/v4
.NET
To use from .NET, install using dotnet add package
:
$ dotnet add package Pulumi.Docker
Reference
For further information, please visit the Docker provider docs or for detailed reference documentation, please visit the API docs.