Terraform Provider - Docker
Find a file
Copilot 26370b6b63
Some checks are pending
Acc Tests / Detect acc-test matrix (push) Waiting to run
Acc Tests / acc-test (push) Blocked by required conditions
Compile Binaries / compile-fast (push) Waiting to run
Compile Binaries / compile (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Unit Tests / unit-test (push) Waiting to run
Website Checks / markdown-link-check (push) Waiting to run
Docs and Website Lint / website-generation (push) Waiting to run
Docs and Website Lint / website-lint-spellcheck-tffmt (push) Waiting to run
Docs and Website Lint / markdown-lint (push) Waiting to run
Avoid docker_container replacement when only daemon default log_opts are present (#888)
* Initial plan

* fix(container): ignore daemon default log_opts when unset

Agent-Logs-Url: https://github.com/kreuzwerker/terraform-provider-docker/sessions/f161d367-0249-44a0-8761-2f1f4d1c54e7

Co-authored-by: Junkern <3775779+Junkern@users.noreply.github.com>

* test(container): cover log_opts omitted vs configured state behavior

Agent-Logs-Url: https://github.com/kreuzwerker/terraform-provider-docker/sessions/f161d367-0249-44a0-8761-2f1f4d1c54e7

Co-authored-by: Junkern <3775779+Junkern@users.noreply.github.com>

* chore: enforce make fmt in copilot instructions

Agent-Logs-Url: https://github.com/kreuzwerker/terraform-provider-docker/sessions/2a852f9f-3abb-4c44-b675-66303adfc827

Co-authored-by: Junkern <3775779+Junkern@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Junkern <3775779+Junkern@users.noreply.github.com>
Co-authored-by: Martin <Junkern@users.noreply.github.com>
2026-04-04 14:20:28 +02:00
.chglog chore: Automate changelog generation [skip ci] 2022-07-14 15:36:05 +02:00
.github Avoid docker_container replacement when only daemon default log_opts are present (#888) 2026-04-04 14:20:28 +02:00
assets docs: update readme with logos and subsections (#235) 2021-06-23 17:33:00 +02:00
docs Add platform support to docker_container for cross-architecture emulation (#886) 2026-04-04 13:25:58 +02:00
examples chore: Prepare 4.0.0 release (#884) 2026-04-03 16:52:39 +02:00
internal Avoid docker_container replacement when only daemon default log_opts are present (#888) 2026-04-04 14:20:28 +02:00
scripts feat: Add build option for additional contexts (#798) 2025-09-30 22:55:12 +02:00
templates Feat: Make buildx builder default (#855) 2026-02-21 13:59:15 +01:00
testdata Add platform support to docker_container for cross-architecture emulation (#886) 2026-04-04 13:25:58 +02:00
tools fix: Switch to proper go tools mechanism to fix website-* workflows. (#399) 2022-07-11 14:55:15 +02:00
.gitignore Add timeout support to docker_registry_image resource (#769) 2025-08-13 14:42:18 +02:00
.go-version chore: update Go version to 1.22 for consistency across workflows, jo… (#613) 2024-05-08 14:59:49 +02:00
.golangci.yml chore: Upgrade golangci-lint to next major version (#686) 2025-04-15 18:54:25 +02:00
.goreleaser-fast.yml fix: Correctly get and set nanoCPUs for docker_container (#771) 2025-08-13 16:33:16 +02:00
.goreleaser.yml feat: Implement using of buildx for docker_image (#717) 2025-05-06 22:21:09 +02:00
.markdownlinkcheck.json chore(ci): Add retryon429 for markdownlint (#736) 2025-06-04 19:51:09 +02:00
.markdownlint.yml feat/doc generation (#193) 2021-05-21 21:30:56 +09:00
.terraform-registry chore: Add file requested by hashicorp (#813) 2025-10-30 22:38:12 +01:00
CHANGELOG.md chore: Prepare 4.0.0 release (#884) 2026-04-03 16:52:39 +02:00
CODE_OF_CONDUCT.md docs: adds coc and contributing 2020-12-24 16:27:35 +01:00
CONTRIBUTING.md chore: update Go version to 1.22 for consistency across workflows, jo… (#613) 2024-05-08 14:59:49 +02:00
GNUmakefile feat: Implement proper parsing of GPU device requests when using gpus… (#881) 2026-04-03 12:54:26 +02:00
go.mod Add platform support to docker_container for cross-architecture emulation (#886) 2026-04-04 13:25:58 +02:00
go.sum feat: Implement docker_exec action (#885) 2026-04-04 00:15:21 +02:00
LICENSE initial commit 2017-06-05 20:59:08 +00:00
main.go feat: Add muxing to introduce new plugin framework (#838) 2026-01-21 23:13:34 +01:00
README.md chore: Prepare 4.0.0 release (#884) 2026-04-03 16:52:39 +02:00
renovate.json5 chore: Exclude examples directory from renovate. 2022-06-22 21:33:56 +02:00

Docker logo Terraform logo

Terraform Provider for Docker

Release Installs Registry License
Go Status Lint Status Go Report Card

Sponsored by Coder

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:

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.0.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

Sponsors

Coder