我想为docker和ansible配置docker映像。我想使用高山作为基本图像。一些Docker映像(例如Alpine)不提供“ / bin / bash”。当打包程序运行该docker映像时,它将继续启动/ bin / bash。这将使构建过程崩溃:
dockerbuild.json:
{
"builders": [
{
"type": "docker",
"image": "alpine:3.8",
"commit": true
}
],
"provisioners": [
{
"type": "ansible",
"user": "root",
"playbook_file": "playbook.yml",
"extra_arguments": [
"--extra-vars",
"ansible_connection=docker"
]
}
]
}
错误:
$> packer build dockerbuild.json
...
==> docker: Starting docker container...
docker: Run command: docker run -v /Users/engi/.packer.d/tmp/packer-docker014300196:/packer-files -d -i -t alpine:3.8 /bin/bash
==> docker: Error running container: Docker exited with a non-zero exit status.
==> docker: Stderr: docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown.
我可以使用“ / bin / sh”或不使用显式shell来手动运行映像:
docker run --rm -i -t alpine:3.8 /bin/sh
docker run --rm -i -t alpine:3.8
您知道我如何打包程序告诉不启动/ bin / bash吗?
答案 0 :(得分:1)
我在文档(惊奇)上找到了解决方案: run_command
https://www.packer.io/docs/builders/docker.html
这对我有用:
{
"builders": [
{
"type": "docker",
"image": "alpine:3.8",
"commit": true,
"run_command": ["-d", "-i", "-t", "{{.Image}}", "/bin/sh"]
}
],
"provisioners": [
{
"type": "ansible",
"user": "root",
"playbook_file": "playbook.yml",
"extra_arguments": [
"--extra-vars",
"ansible_connection=docker"
]
}
]
}