'Packer unable to read shell script while using Docker plugin
I am trying to create a docker image using Packer. However, when I am trying to use the shell provisioner it is unable to find the shell script.
learn-packer.docker.terraform: /bin/sh: /tmp/script_8997.sh: not found
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?"
What could be the reason for packer to not able to find the script ?
Solution 1:[1]
I ran into the same issue and have managed to find the cause:
The error is quite misleading; the actual file not being found is the binary pointed to in the shebang, not the script itself.
Alpine doesn't have bash installed by default, so using it as the shell will fail. Using /bin/sh instead fixed it for me, i.e.:
#!/bin/sh
echo "How are you?"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nocturne92 |
