利用terraform完成docker镜像拉取,以及应用部署

参考学习: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
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值