2021-06-23 11:33:00 -04:00
< 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 >
< a href = "https://kreuzwerker.de" >
< img src = "https://raw.githubusercontent.com/kreuzwerker/terraform-provider-docker/master/assets/xw-logo.png" alt = "Kreuzwerker logo" title = "Kreuzwerker" align = "right" height = "100" / >
< / a >
# Terraform Provider for Docker
2017-06-05 16:59:08 -04:00
2021-07-11 08:17:14 -04:00
[](https://github.com/kreuzwerker/terraform-provider-docker/releases)
[](https://registry.terraform.io/providers/kreuzwerker/docker)
[](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs)
[](https://github.com/kreuzwerker/terraform-provider-docker/blob/main/LICENSE)
[](https://github.com/kreuzwerker/terraform-provider-docker/actions)
[](https://github.com/kreuzwerker/terraform-provider-docker/actions)
[](https://goreportcard.com/report/github.com/kreuzwerker/terraform-provider-docker)
2017-06-05 16:59:08 -04:00
- Website: https://www.terraform.io
2020-12-25 04:20:14 -05:00
- Provider: [kreuzwerker/docker ](https://registry.terraform.io/providers/kreuzwerker/docker/latest )
- Slack: [@gophers/terraform-provider-docker ](https://gophers.slack.com/archives/C01G9TN5V36 )
2017-06-05 16:59:08 -04:00
2020-12-24 10:27:42 -05:00
## Requirements
2020-12-27 05:18:22 -05:00
- [Terraform ](https://www.terraform.io/downloads.html ) >=0.12.x
2022-09-01 09:35:14 -04:00
- [Go ](https://golang.org/doc/install ) 1.18.x (to build the provider plugin)
2017-06-05 16:59:08 -04:00
2020-12-24 10:27:42 -05:00
## Building The Provider
2017-06-05 16:59:08 -04:00
```sh
2021-02-26 13:21:14 -05:00
$ git clone git@github.com:kreuzwerker/terraform-provider-docker
2017-11-21 04:14:07 -05:00
$ make build
2017-06-05 16:59:08 -04:00
```
2017-11-21 04:14:07 -05:00
2020-12-24 10:27:42 -05:00
## Example usage
2021-06-23 11:33:00 -04:00
2022-09-05 09:44:30 -04:00
Take a look at the examples in the [documentation ](https://registry.terraform.io/providers/kreuzwerker/docker/2.21.0/docs ) of the registry
2021-06-23 11:33:00 -04:00
or use the following example:
2017-11-21 04:14:07 -05:00
```hcl
2020-12-24 10:27:42 -05:00
# Set the required provider and versions
terraform {
required_providers {
2020-12-26 08:44:09 -05:00
# We recommend pinning to the specific version of the Docker Provider you're using
2020-12-24 10:27:42 -05:00
# since new versions are released frequently
docker = {
source = "kreuzwerker/docker"
2022-09-05 09:44:30 -04:00
version = "2.21.0"
2020-12-24 10:27:42 -05:00
}
}
2017-11-21 04:14:07 -05:00
}
2020-12-24 10:27:42 -05:00
# Configure the docker provider
provider "docker" {
}
2018-09-28 10:18:48 -04:00
2020-12-24 10:27:42 -05:00
# Create a docker image resource
# -> docker pull nginx:latest
2021-03-25 06:50:57 -04:00
resource "docker_image" "nginx" {
name = "nginx:latest"
2020-12-24 10:27:42 -05:00
keep_locally = true
}
2018-09-28 10:18:48 -04:00
2020-12-24 10:27:42 -05:00
# Create a docker container resource
2021-06-21 03:24:02 -04:00
# -> same as 'docker run --name nginx -p8080:80 -d nginx:latest'
2021-03-25 06:50:57 -04:00
resource "docker_container" "nginx" {
name = "nginx"
2022-09-05 09:14:45 -04:00
image = docker_image.nginx.image_id
2021-06-21 03:24:02 -04:00
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
}
}
2020-12-24 10:27:42 -05:00
}
2021-02-26 13:21:14 -05:00
```
2021-06-23 11:33:00 -04:00
## 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 ](CONTRIBUTING.md )
## License
2021-12-03 05:38:55 -05:00
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 ](LICENSE ).
## Stargazers over time
[](https://starchart.cc/kreuzwerker/terraform-provider-docker)