I want to use the host ip address in container, how should I achieve this in dockerfile way?
FROM my_image
ENV http_proxy <the_host_ip_address:port>
ENV https_proxy <the_host_ip_address:port>
I want to use the host ip address in container, how should I achieve this in dockerfile way?
FROM my_image
ENV http_proxy <the_host_ip_address:port>
ENV https_proxy <the_host_ip_address:port>
2
Answers
You can pass any argument variables while building a docker-image and use them in the Dockerfile. For example:
And the command for building a docker-image will look like this:
There is a useful article on the baeldung.com
UPD
I’ve already found a more detailed answer. Look at this.
Here is one way to set the host IP address in the Dockerfile:
And then when building the image, you would pass the –build-arg flag to set the HOST_IP arg:
This will set the HOST_IP arg to the IP address of the host machine during build time.
The advantage of this method is that the host IP doesn’t need to be hardcoded in the Dockerfile, it is set at build time.