I have the following Dockerfile:
FROM ubuntu:bionic
RUN apt-get update -y && apt-get install -y nginx
EXPOSE 80
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
Building the container and running it through the following commands works:
$ docker build -t web:1.0 .
$ docker run -itd -p 8200:80 --name webserver1 web:1.0
I made an equivalent Packer file as follows:
packer {
required_plugins {
docker = {
version = ">= 1.0.1"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "ubuntu" {
image = "ubuntu:bionic"
commit = true
changes = [
"EXPOSE 80",
"CMD [\"/usr/sbin/nginx\", \"-g\", \"daemon off;\"]"
]
}
build {
name = "learn-packer"
sources = [
"source.docker.ubuntu"
]
provisioner "shell" {
inline = [
"apt-get -y update",
"apt-get install -y nginx",
]
}
post-processors {
post-processor "docker-tag" {
repository = var.docker_repo
tags = ["1.1"]
}
}
}
I’m creating the image with packer build .
When I run the generated image through Docker
docker run -itd -p 8201:80 --name webserver2 xxx/web:1.1
I get the following error:
usr/sbin/nginx: 1: usr/sbin/nginx: Syntax error: ")" unexpected
Amyone can see what is wrong?