Docker Uses Environment Variables to Set Up Extra Hosts
Source: Internet
Author: User
Keywordsextra hosts docker hosts of extra docker environment variables
I am using docker compose to run my application. For this, I need to set up the host inside the container (it depends on the environment I am running in).
I tried to use $SERVER_IP or $(SERVER_IP) to replace variable references, but it didn't work.
I created a file .env, added a single line HOST = test.example.com, and then did this in docker-compose:
extra_hosts:
-myip:${HOST}
docker-compose config then shows
extra_hosts:
myip: test.example.com
For this, I followed the documentation on .env files in Docker-compose environment variables
UPDATE
According to the Docker documentation,
Note: If your service specifies a build option, variables defined in environment files will not be automatically visible during the build.
Use the args sub-option of build to define build-time environment variables.
It basically means that if you put variables in the .env file, you can use them in docker-compose.yml to replace them, but if you use the env_file option for a specific container, you can only see the variables inside the Docker container, not In the build. It is also logical, env_file replaces docker run --env-file = FILE...and nothing else.
Therefore, you can only put your values into .env. Or, as William described, you can use the host's environment variables.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.