我刚开始使用 Packer,并希望构建 AMI 和 Docker 镜像。
问题是,Docker 的 Ubuntu 镜像没有 sudo
命令,因此会出现以下错误:
docker: /tmp/script_2085.sh: 3: /tmp/script_2085.sh: sudo: not found
是否有办法为 shell
provisioner 添加一些“条件”,以便根据 builder
来运行具有或不具有 sudo
的命令?
目前,我的模板中有:
...
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo apt-get update",
"sudo apt-get install -y nginx"
]
}]
...
添加类似以下内容:
if which sudo; then sudo apt-get update && sudo apt-get install -y nginx; else apt-get update && apt-get install -y nginx; fi
看起来这是一个奇怪的解决方案... 我相信 - Packer有更好的方法来做到这一点。