background
In the virtual machine environment, if you want to customize hosts, you can directly modify the /etc/hosts file.
In the cloud-native environment, there is also such a requirement, and I want to add a custom hosts configuration to the started container. For example
, 1. When the DNS configuration and other options are unreasonable, such as the resolved IP address is incorrect.
2. Overwrite the resolution of the host name or add the resolution of some host names
solve
There are different solutions for different environments.
- Docker environment: add –add-host option when running
- Kubernetes environment: use the hostAlias tag
- RainBond environment: use the ES_HOST_XXX environment variable, essentially the same as above
Docker environment
In the Docker environment, when running a new container directly, you can use –add-host to specify the mapping relationship between the host and the IP.