it is possible to map the .env environment variables to ARGS to be used by the Dockerfile during build.
docker-compose.yml
version: "x"
services:
xxx:
build:
# there is the space between context and .
context: .
dockerfile: ./Dockerfile
args:
- PORT=${PORT}
volumes:
...
Dockerfile
FROM xx
ARG PORT
ENV PORT "$PORT"
EXPOSE ${PORT}
...
In the root folder, you can define the ARG in .env.