我正在尝试使用Packer创建一个docker映像。但是,当我尝试使用shell提供程序时,它找不到shell脚本。
learn-packer.docker.terraform:/bin/sh:/tmp/script_8997.sh:未找到
packer {
required_plugins {
docker = {
version = ">= 0.0.7"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "terraform" {
image = var.docker_image
commit = true
}
build {
name = "learn-packer"
sources = [
"source.docker.terraform",
]
provisioner "shell" {
script = "scripts/test.sh"
pause_before = "5s"
}
provisioner "shell" {
inline = [
"apk update",
"apk add bash curl",
]
}
post-processor "docker-tag" {
repository = "learn-packer"
tags = ["packer-test"]
only = ["docker.terraform"]
}
}
variable "docker_image" {
type = string
default = "hashicorp/terraform:latest"
}
cat scripts/test.sh
#!/usr/bin/bash
echo "How are you?"
packer找不到脚本的原因是什么?
我遇到了同样的问题,并设法找到了原因:
这个错误很容易引起误解;找不到的实际文件是shebang中指向的二进制文件,而不是脚本本身。
Alpine默认情况下没有安装bash,因此将其用作shell将失败。使用/bin/sh为我修复了它,即:
#!/bin/sh
echo "How are you?"