When you’re using Hashicorp Nomad + Consul Connect the docker extra_hosts
argument is not propagated to containers.
Here is a quick workaround to append custom values to /etc/hosts of your containers.
Add the following task in your group, task will start first and exit (0).
task "extra-etc-hosts" {
driver = "docker"
config {
image = "alpine:latest"
command = "/bin/sh"
args = ["local/extra_hosts.sh"]
security_opt = ["label=disable"]
}
template {
data = <<EOF
cat <<EOT >> /etc/hosts
10.10.10.10 my.custom-domain.tld
EOT
EOF
destination = "local/extra_hosts.sh"
}
lifecycle {
hook = "prestart"
}
}
Reference of the bug that will soon be fixed, I hope https://github.com/hashicorp/nomad/issues/11056
Leave a Reply