I've tried this a few ways even tried naming the file exactly but still wont work.
docker-compose up --build
Error:
WARNING: The APP_SERVER_PORT variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_PORT variable is not set. Defaulting to a blank string.
ERROR: The Compose file './../docker-compose.yml' is invalid because:
services.app.expose is invalid: should be of the format 'PORT[/PROTOCOL]'
services.server.expose is invalid: should be of the format 'PORT[/PROTOCOL]'
services.app.ports contains an invalid type, it should be a number, or an object
services.server.ports contains an invalid type, it should be a number, or an object
my folder structure
server
app
docker.compose.yml
env.development
env.production
Docker compose file
version: '3'
services:
server:
build: ./server
env_file:
- ./var.env
expose:
- ${APP_SERVER_PORT}
ports:
- ${APP_SERVER_PORT}:${APP_SERVER_PORT}
command: yarn run dev
app:
expose:
- ${REACT_APP_PORT}
build: ./client
env_file:
- ./var.env
ports:
- ${REACT_APP_PORT}:${REACT_APP_PORT}
links:
- server
command: yarn run start
I have even tried
env_file:
- ./.env.development
My .env.development file
APP_SERVER_PORT=3001
REACT_APP_PORT=3000
CodePudding user response:
env_file
only sets environment variables on the running container, not interpolated within the Compose file.
To get interpolation for the compose file, your local shell needs to have those variables defined.
REACT_APP_PORT=3000 APP_SERVER_PORT=3001 docker-compose up --build
You can use shell extentions like direnv
to simplify that process, otherwise, Makefile
's that run the above command are typically used for portability.