You can not manipulate hosts file since it is being managed by docker daemon. To prevent access problems/errors when you manipulate linux system files in docker, you can add "copy" parameter for sed command in your install script such as:
sed -i -c ...
But when you run the container, you will see the unchanged original file. You can think about applying these kind of tricks in Entrypoint or CMD command sections of Dockerfile, details are at the end.
There are other solutions but valid only during docker build:
2
Answers
You are missing
sudo
sudo ./install && source $([ $SHELL = "/bin/zsh" ] && echo ~/.zshrc || echo ~/.bashrc);
You can not manipulate hosts file since it is being managed by docker daemon. To prevent access problems/errors when you manipulate linux system files in docker, you can add "copy" parameter for sed command in your install script such as:
But when you run the container, you will see the unchanged original file. You can think about applying these kind of tricks in Entrypoint or CMD command sections of Dockerfile, details are at the end.
There are other solutions but valid only during docker build:
Docker binary has an option "–add-host":
https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file—add-host
If you are working with AWS you have directly corresponded feature "extraHosts":
https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html
If you need the modification persistent in container run time you only have the option to modify Entrypoint or CMD:
https://stackoverflow.com/a/40430182/1980180