Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# docker_provider.tf
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 2.13.0"
}
}
}
provider "docker" {}
# docker_resources.tf
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = var.container_name
ports {
internal = 80
external = 8000
}
}
# variables.tf
variable "container_name" {
description = "Value of the name for the Docker container"
type = string
default = "Nginx_Container"
# outputs.tf
output "container_id" {
description = "ID of the Docker container"
value = docker_container.nginx.id
}
output "image_id" {
description = "ID of the Docker image"
value = docker_image.nginx.id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment