参考学习:https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs
Please utilize terraform to accomplish the below tasks:
Pull the ubuntu:latest docker image on docker-host.
Using another image - httpd:latest , deploy a container with name foo and hostname webserver . Bind the container port 80 to its host port 80
NOTE: Please ensure to apply the changes before validating.
Utilize /home/bob/terra-resources directory to store your Terraform configuration files.
SSH credentials for docker-host:
User: admin
Password: admin
Container name set to “foo”
Hostname set to “webserver”
Port bindings set ?
Image “ubuntu:latest” pulled using terraform?
Container “foo” uses image “httpd:latest” ?
provider.tf
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
}
}
provider "docker" {
host = "ssh://admin@docker-host:22"
ssh_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"]
}
ubutu.tf
resource "docker_image" "ubuntu" {
name = "ubuntu:latest"
}
~
httpd.tf
resource "docker_image" "httpd" {
name = "httpd:latest"
}
# Create a container
resource "docker_container" "foo" {
image = docker_image.httpd.latest
name = "foo"
hostname = "webserver"
ports {
internal = 80
external = 80
}
}