.env file with APP_PORT=8080 and the following docker-compose.yml snippet, what will be the exposed port on the host after running docker-compose up?version: '3.8' services: web: image: nginx ports: - "${APP_PORT}:80"
Docker Compose automatically loads variables from the .env file in the same directory. The ${APP_PORT} in docker-compose.yml is replaced by 8080, so port 8080 on the host maps to port 80 in the container.
.env file in Docker and Docker Compose projects?The .env file holds environment variables that Docker Compose reads to substitute variables in the compose file or pass into containers. It helps keep configuration flexible and separate from code.
.env file for Docker Compose?In .env files, to represent newlines inside a variable, you must use escaped newline characters \n inside quotes. Option A correctly uses double quotes and escaped newlines.
.env file with DB_USER=admin but when running docker-compose up, the variable ${DB_USER} in docker-compose.yml is empty. What is the most likely cause?Docker Compose only automatically loads the .env file if it is in the same directory as the docker-compose.yml file. If it is elsewhere, variables won't be substituted.
.env files used with Docker Compose?It is best to keep sensitive data out of version control by adding .env files to .gitignore. This prevents accidental exposure of secrets. Other methods like encryption or host-only variables are more complex.