Terraform File:
terraform {
required_providers {
docker = {
source = “terraform-providers/docker”
}
}
required_version = “>= 0.13”
}
resource “docker_image” “nginx” {
name = “nginx:latest”
}
resource “docker_container” “nginx” {
image = docker_image.nginx.latest
name = “tutorial”
ports {
internal = 80
external = 80
}
}
Use terraform init command to initialize the provider.
Check the changes using the terraform plan command.
Terraform plan
To apply those changes use the terraform apply command.
terraform apply
Task by Trainer:
Task 1:
- Create a httpd container using image docker.io/httpd
- Name container as “myweb”
- Forward it to port “8080”