score:1
The .env
file is a special, name-reserved file for docker-compose to set defaults for environment variables, so if you want to use it, you should rather not specify in your compose file, or use a different filename (eg: myservice.env
) for your env_file
section.
web_front:
env_file:
- webfront.env
...
The docker docs mentions vaguely this under https://docs.docker.com/compose/env-file/ at the Compose file and CLI variables / Notes section
Environment variables defined in the .env file are not automatically visible inside containers.
To set container-applicable environment variables, follow the guidelines in the topic Environment variables in Compose, which describes how to pass shell environment variables through to containers, define environment variables in Compose files, and more at:
score:2
For the environment variables to be passed onto the dockerfile from the docker compose build stage, you have to use args: in docker-compose build step. Example below
web_front:
build:
context: Web Front-CRA
args:
NODE_PATH=./src/
ports:
- "${WEB_FRONT_PORT}:6000"
env_file:
- .env
volumes:
- /usr/app/node_modules
- ./Web Front-CRA:/usr/app
corresponding dockerfile
FROM node:10-alpine
ARG NODE_PATH
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:1.15
COPY --from=0 /usr/app/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=0 /usr/app/build /usr/share/nginx/html
EXPOSE 6000
Access it in the dockerfile using $NODE_PATH
. PS I am using an environment variable here and not an envfile. But I hope you get the point. Cheers.
Source: stackoverflow.com
Related Query
- Create React App Build and Docker-Compose do not pass env variables
- Docker fails to build - Create React App + Tailwind /bin/sh: craco: not found
- Docker Create react app hot reload not working
- Why does production build of React app (with Webpack and Babel) use wrong development env with HMR, which causes errors?
- Create React App not installing, showing an error and aborting installation
- How to inject port and host using ENV variable in Create React App Proxy settings?
- create react app not loading css background images in dev or build
- How to analyze create react app build size and reduce it?
- Nginx and Create React App (with React Router) full routes not working
- Docker with create react app is not updating changes
- How to determine the order of css in my create react app build with webpack and customize-cra?
- Docker compose not properly copying files to run react app
- How to deploy React app with docker and serve -s build
- Problem with npm build and babel in React Create App
- React app set proxy not working with docker compose
- Create react app with npx that uses classes and not hooks
- Not able to figure out why docker compose up is not running my React JS App
- Create React App PWA ERROR: Does not register a service worker that controls page and start_url
- Trying to deploy react app on aws amplify but keep getting a "Base Directory not specified for artifacts, unable to create build artifact."
- React App - Why m count down is showing a dot whent the hours are equals to zero? And my minute is not 00 when pass of 59
- Create React App and Global Types not being picked up
- I create a build of my react app and connected with electron.js. now how to connect my backend from server folder with electron
- Create a react app and use a npm start command but it is not working
- Docker Compose with Docker Toolbox: Node, Mongo, React. React app not showing in the said adress
- React Create Application production build and CSS variables in IE11
- Docker compose can't correct build react app
- Bitbucket pipeline is failing and not letting me create the react build
- Create React App fails to build inside docker
- Not able to create an optimized build for my React app in the build folder
- create react app not picking up .env files?
More Query from same tag
- React + Firebase Form Validation if user does not exist
- TS2322 - false | Element is not assignable to type ReactElement. Error does not consistently appear in app?
- Why is the attribute seemingly being reverted?
- How can a function value is displayed in a HTML tag with a return value from addEventListerner click?
- Why does the jest mock function not getting executed in my test with react testing library?
- My date function is not working on firefox but works on chrome
- React-datepicker validation using react-hook-form
- I want to display div tags according to the type of Props value
- Gatsby.js blog is appending '/blog' twice to a post
- react-redux flow type definitions for ownProps, mapStateToProps and mapDispatchToProps
- ES6 features in React Native
- In Svelte, is there a way to undo invalid user input, without changing the state?
- cant access Api response in react js
- Material-UI Select, how to apply :focus-within styling on the select when the input is clicked?
- How can I access Electron's process object from my react app?
- Continuously watch for a condition to be true without render in ReactJs
- Nested Grid MUI react
- Updating the state of an array after search reactjs
- React JS - event handling for mapped objects
- useCallback vs. useMemo and when to use them
- cookie and security in react application
- React Array in State updating late
- How to access the redux store within the redux form
- Metamask RPC methods do not exist
- how to have same path for multiple component with react-router
- Adding class for expanded rows in react-table
- How to structure component export without export default?
- Dynamic Forms in React, Cannot read property 'map' of undefined
- ReactJS : How to wrap knockoutJS page inside React component
- React show Material-UI Tooltip only for text that has ellipsis