kaniko
kaniko copied to clipboard
/etc/hosts in docker image ignored
Actual behavior Kaniko is ignoring /etc/hosts configured by docker
Expected behavior Kaniko should respect /etc/hosts
To Reproduce Steps to reproduce the behavior:
- run kaniko docker image with extrahosts for redirecting registry
Additional Information
This is caused by missing /etc/nsswitch.conf
: echo "hosts: files dns" > /etc/nsswitch.conf``
See https://github.com/golang/go/issues/22846 for details
Thanks! Would you like to try fixing this? It should be as simple as modifying the Dockerfiles in https://github.com/GoogleContainerTools/kaniko/blob/master/deploy/Dockerfile
I think adding this file is not enough. When i use a multistage build, /etc/
will get deleted.
We need a Workaround for redirecting our /etc
to /kaniko/etc/
.
Unpacking a image will overwrite that files too.
Hmm, if you mount it in as a volume during the run (either docker or k8s) then it should not get overwritten. Would that work for your use case?
that could work, does docker mount the hosts file or do i have to mount that when i run kaniko container?
@ViceIce you will have to mount it explicitly
may be we can have a '--add-host' option like docker ?
I found a workaround that worked for me that I wanted to share:
Background:
Docker does not allow to modify the /etc/host at build time. The solution is to use --extra-hosts to provide domain resulution while building. Kaniko does not support this.
Note This is not a solution just a dirty workaround
I will assume that most of you will run kaniko in CI. I use GitLab
So we can override the entrypoint and run a before_script:
Assuming you habe a domains.list file (however you generate or get it)
Before running kaniko do:
for(line in "$(<domains.list)") {
echo "127.0.0.1 ${line}" >> /etc/hosts
}
Now my domains in the reverse proxy config are resolvable and the config test passes.
for(line in "$(<domains.list)") { echo "127.0.0.1 ${line}" >> /etc/hosts }
is this workaround works? the before_script seems wrong?