Skip to content

Instantly share code, notes, and snippets.

@SanthoshNC
Created August 23, 2021 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SanthoshNC/aeaeba0383451ea61c460fadd9f79cdf to your computer and use it in GitHub Desktop.
Save SanthoshNC/aeaeba0383451ea61c460fadd9f79cdf to your computer and use it in GitHub Desktop.
# 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