期待
Here is my packer file:
{
"builders" : [
{
"type": "docker",
"image": "nginx",
"commit": "true"
}
],
"provisioners" : [
{
"type": "file",
"source": "./index.html",
"destination": "/usr/share/nginx/html/index.html"
}
],
"post-processors" : [
{
"type": "docker-tag",
"repository": "repo",
"tag": "latest"
}
]
}当packer从上面输出的工件(即使用命令 -d -p 8080:80 -name web repo )运行自定义nginx映像时,为上述文件构建,观察到码头容器出现时,端口被占用,但nginx进程没有在码头容器内运行,因为指定端口上无法访问哪些html内容。网址:http://localhost:8080
但是,上面创建自定义的nginx停靠库映像并运行码头容器的场景是使用下面的Dockerfile执行的,它运行得很好,即码头容器出现,端口被占用,HTML内容也是可访问的:
以下是Dockerfile:
FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html我需要使用封隔器码头建设者,有什么可能的问题吗?是否有任何限制使用码头建设者与封隔器或与nginx?
发布于 2021-07-07 01:05:42
问题是,封隔器在它的所有荣耀覆盖入口点。封隔器的工作方式是将其“剥离”到运行的容器中,并提交给它。所以它实际上不使用码头建造系统。
当您提交容器时,映像将获得启动容器的入口点和cmd,如果是packer,默认情况下它将入口点设置为/bin/sh。
一种选择是不让它改变入口点。我已经从默认命令中删除了--entrypoint。
source "docker" "nginx" {
image = "nginx"
commit = true
run_command = ["-d", "-i", "-t", "--", "{{.Image}}"]
}不过,我不知道这是否总是可行的。我认为nginx入口点是特殊的,因为它只会在最后执行参数,如果nginx不是第一个参数,它就什么也不做了。
exec "$@"也许有时你需要给它一个外壳入口点,以使封隔器在图像中正常工作。然后,恢复更改数组中的cmd和entrypoint。奇怪的是,当我这样做时,我需要恢复CMD,否则就会是null。
source "docker" "nginx" {
image = "nginx"
commit = true
changes = [
"ENTRYPOINT [\"/docker-entrypoint.sh\"]",
"CMD [\"nginx\", \"-g\", \"daemon off;\"]"
]
}下面是一个完整的工作示例
packer {
required_plugins {
docker = {
version = ">= 1"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "nginx" {
image = "nginx"
commit = true
# either don't overwrite the entrypoint
run_command = ["-d", "-i", "-t", "--", "{{.Image}}"]
# or restore it
changes = [
"ENTRYPOINT [\"/docker-entrypoint.sh\"]",
"CMD [\"nginx\", \"-g\", \"daemon off;\"]"
]
}
build {
sources = [
"source.docker.nginx",
]
provisioner "file" {
source = "./index.html"
destination = "/usr/share/nginx/html/index.html"
}
post-processor "docker-tag" {
repository = "web"
}
}https://stackoverflow.com/questions/66064621
复制相似问题