I am an infra admin for providing docker images to developers.
I created "A" images and then tell docker run command is
docker run --add-host=a-lic:10.0.0.1 --add-host=b-lic:10.0.0.2 A
every developers request to me, please remove --add-host option because it is long. So I want to edit /etc/hosts file when docker build if possible.
I find out docker build --add-host
option newly create from 17.04
but it does not work as my expected.
someone said --add-host option is for only during building image and another said --add-host option will work as below (my thoughts).
docker build --add-host=a-lic:10.0.0.1 -t A .
docker run -it A
And docker's documentation is not sufficient for this.
$ docker build --help
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
What is the correct??
It's by design (see https://github.com/moby/moby/issues/34078#issuecomment-314798584 / https://github.com/moby/moby/pull/30383#issuecomment-314797629); the --add-host
feature during build is designed to allow overriding a host during build, but not to persist that configuration in the image.
If it would persist in the image;
google.com 123.123.123.123
?)The person running an image should remain in control over overriding hosts, not the image author; it's a runtime configuration.
Possible solutions For your situation;
docker-compose.yml
to your developers. The docker compose file allows you to specify all the options that should be used when starting a container, so developers could just docker compose up
to start the container with all the options they need to set.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With