编程知识 cdmana.com

Choreograph terradocker

One background

Docker The provider is used to communicate with Docker Images and containers . It USES Docker API To manage Docker The life cycle of the container . because Docker Provider usage Docker API, So it's not just immediately compatible with a single server Docker, And it's instantly compatible Swarm And any other Docker Compatible API host .

Two operation

2.1 Code

terraform {  required_providers {    docker = {      source = "kreuzwerker/docker"      version = "~> 2.13.0"    }  }}provider "docker" {}resource "docker_image" "nginx" {  name = "nginx:latest"  keep_locally = false}resource "docker_container" "nginx" {  image = docker_image.nginx.latest  name = "tf-docker-containter"  ports {    internal = 80    external = 8000  }}

2.2 perform

terraform apply

  • View results

3、 ... and other

You can also use it ssh Protocol to connect to the on the remote computer docker host . The configuration is as follows :

provider "docker" {  host     = "ssh://[email protected]:22"  ssh_opts = ["-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null"]}

Reference link

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://cdmana.com/2022/134/202205141315108647.html

Scroll to Top