gpt4 book ai didi

docker - Terraform无法启动Docker服务

转载 作者:行者123 更新时间:2023-12-02 18:15:37 25 4
gpt4 key购买 nike

我是第一次使用Terraform和Packer。我正在尝试使用内置的Docker创建适用于CentOS的AWS AMI。从下面的包装器脚本可以看出,我要做的就是运行许多docker文档中描述的yum命令,以安装docker。

{
"builders": [
{
"type": "amazon-ebs",
"profile": "digital",
"source_ami": "ami-061b1560",
"instance_type": "t2.micro",
"ssh_username": "centos",
"ami_name": "centos-docker {{timestamp}}"
}
],

"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo yum install -y yum-utils device-mapper-persistent-data lvm2",
"sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo",
"sudo yum makecache fast",
"sudo yum install docker-ce"
]
}]

}

然后,我在terraform脚本中使用由上述脚本创建的AMI,并添加 local-exec Provisioners以启动docker服务
provider "aws" {
profile = "digital"
region = "eu-west-1"
}

resource "aws_instance" "chat-server" {
ami = "ami-XXXXXX"
instance_type = "t2.micro"

provisioner "local-exec" {
command = "sudo systemctl start docker"
}
}

当我运行 terraform apply时,它卡在尝试启动docker服务的命令周围。
aws_instance.chat-server: Creating...
ami: "" => "ami-609f6919"
associate_public_ip_address: "" => "<computed>"
availability_zone: "" => "<computed>"
ebs_block_device.#: "" => "<computed>"
ephemeral_block_device.#: "" => "<computed>"
instance_state: "" => "<computed>"
instance_type: "" => "t2.micro"
ipv6_address_count: "" => "<computed>"
ipv6_addresses.#: "" => "<computed>"
key_name: "" => "<computed>"
network_interface.#: "" => "<computed>"
network_interface_id: "" => "<computed>"
placement_group: "" => "<computed>"
primary_network_interface_id: "" => "<computed>"
private_dns: "" => "<computed>"
private_ip: "" => "<computed>"
public_dns: "" => "<computed>"
public_ip: "" => "<computed>"
root_block_device.#: "" => "<computed>"
security_groups.#: "" => "<computed>"
source_dest_check: "" => "true"
subnet_id: "" => "<computed>"
tenancy: "" => "<computed>"
volume_tags.%: "" => "<computed>"
vpc_security_group_ids.#: "" => "<computed>"
aws_instance.chat-server: Still creating... (10s elapsed)
aws_instance.chat-server: Still creating... (20s elapsed)
aws_instance.chat-server: Still creating... (30s elapsed)
aws_instance.chat-server: Provisioning with 'local-exec'...
aws_instance.chat-server (local-exec): Executing: /bin/sh -c "sudo
systemctl start docker"
Password:aws_instance.chat-server: Still creating... (40s elapsed)
aws_instance.chat-server: Still creating... (50s elapsed)
aws_instance.chat-server: Still creating... (1m0s elapsed)
.
.
.
aws_instance.chat-server: Still creating... (9m0s elapsed)
aws_instance.chat-server: Still creating... (9m10s elapsed)

Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down...
stopping apply operation...

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

我在这里做错了什么?

最佳答案

您使用了错误的预配器,应该使用remote-exec

关于docker - Terraform无法启动Docker服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45533958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com