Skip to content
Fork

terraform-provider-docker

Terraform Docker provider

0

Stars

0

Forks

0

Watchers

0

Issues

11568

Size (KB)

master

Branch

Files

Source on GitHub

Browse the folder structure on GitHub

File tree for this repository will appear here after the next data sync. Meanwhile you can open the full folder listing directly on GitHub.

<a href="https://docker.com">
<img src="https://raw.githubusercontent.com/kreuzwerker/terraform-provider-docker/master/assets/docker-logo.png" alt="Docker logo" title="Docker" align="right" height="100" />
</a>
<a href="https://terraform.io">
<img src="https://raw.githubusercontent.com/kreuzwerker/terraform-provider-docker/master/assets/terraform-logo.png" alt="Terraform logo" title="Terraform" align="right" height="100" />
</a>

Terraform Provider for Docker

Release</a>
Installs</a>
Registry</a>
License</a>
Acc Tests</a>
golangci-lint</a>
Go Report Card</a>

Sponsored by Coder

What You Can Manage With This Provider

This provider covers more than basic Docker images and containers. With Terraform, you can manage:

Compose applications with docker_compose
Image builds and registry workflows with docker_image, docker_registry_image, and docker_tag
Buildx builders for advanced multi-platform builds with docker_buildx_builder
Swarm services with docker_service
Runtime resources such as docker_container, docker_network, and docker_volume
Supporting platform objects like docker_config, docker_secret, and docker_plugin
Operational actions such as docker_exec, docker_image_import, docker_image_load, docker_image_save, docker_container_export and docker_system_prune,

Available data sources include images, image tags and manifests, containers, networks, plugins, and container logs. See the full provider documentation for the complete resource and data source list.

Documentation

The documentation for the provider is available on the Terraform Registry.
You need at least Terraform 1.1.5 to use this provider.

Migration guides:
Do you want to migrate from v3.x to v4.x? Please read the V3 - V4 migration guide


Example usage

Take a look at the examples in the documentation of the registry
or use the following example:

# Set the required provider and versions
terraform {
required_providers {
# We recommend pinning to the specific version of the Docker Provider you're using
# since new versions are released frequently
docker = {
source = "kreuzwerker/docker"
# or if you want to pull from opentfu
source = "registry.opentofu.org/kreuzwerker/docker"
version = "4.5.0"
}
}
}

Configure the docker provider


provider "docker" {
}

Create a docker image resource


-> docker pull nginx:latest


resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = true
}

Create a docker container resource


-> same as 'docker run --name nginx -p8080:80 -d nginx:latest'


resource "docker_container" "nginx" {
name = "nginx"
image = docker_image.nginx.image_id

ports {
external = 8080
internal = 80
}
}

Or create a service resource


-> same as 'docker service create -d -p 8081:80 --name nginx-service --replicas 2 nginx:latest'


resource "docker_service" "nginx_service" {
name = "nginx-service"
task_spec {
container_spec {
image = docker_image.nginx.repo_digest
}
}

mode {
replicated {
replicas = 2
}
}

endpoint_spec {
ports {
published_port = 8081
target_port = 80
}
}
}

Building The Provider

Go 1.18.x (to build the provider plugin)

$ git clone git@github.com:kreuzwerker/terraform-provider-docker
$ make build

Contributing

The Terraform Docker Provider is the work of many of contributors. We appreciate your help!

To contribute, please read the contribution guidelines: Contributing to Terraform - Docker Provider

License

The Terraform Provider Docker is available to everyone under the terms of the Mozilla Public License Version 2.0. Take a look the LICENSE file.

Stargazers over time

Stargazers over time</a>

Sponsors

Coder</a>

Repository metadata

Clone this repository

More public repositories