创建一个 main.tf
文件,写入以下内容:
terraform {
required_providers {
docker = {
source = “kreuzwerker/docker”
}
}
}
provider “docker” {}
resource “docker_image” “nginx” {
name = “nginx:latest”
keep_locally = false
}
resource “docker_container” “nginx” {
image = docker_image.nginx.latest
name = “tutorial”
ports {
internal = 80
external = 8000
}
}
根据 main.tf
初始化项目:
$ terraform init
Initializing the backend…
Initializing provider plugins…
-
Finding latest version of kreuzwerker/docker…
-
Installing kreuzwerker/docker v2.12.2…
-
Installed kreuzwerker/docker v2.12.2 (self-signed, key ID 24E54F214569A8A5)
Partner and community providers are signed by their developers.
If you’d like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run “terraform init” in the futu