I am trying to create a .env-file in the Dockerfile using the following line:
RUN env | grep "REACT_APP" >> .env
I'm getting this error:
The command '/bin/sh -c env | grep "REACT_APP" >> .env' returned a non-zero code: 1
Does anyone know how to solve this?
EDIT:
Full Dockerfile:
FROM node:11.2-alpine
EXPOSE 5000
ENV NPM_CONFIG_LOGLEVEL warn
RUN ['/bin/sh', '-c', 'env | grep "REACT_APP" >> .env']
RUN npm install -g serve
CMD serve -s build -n
# Separate layer for dependencies, it will speedup build
COPY package.json package.json
RUN npm install
COPY . .
RUN npm run build --production
#TODO: Maybe there is another way to include it to build?
#Legacy redirects via native serve options (https://github.com/zeit/serve-handler#redirects-array)
RUN cp serve.json build/
Apparently you don't have REACT_APP
defined at all. As the command:
RUN env| grep REACT_APP >> .env
Will fail with the following error, in case you don't have it defined already.
The command '/bin/sh -c env| grep REACT_APP >> .env' returned a non-zero code: 1
Also no need to write it as
RUN ['/bin/sh', '-c', 'env | grep "REACT_APP" >> .env']
This format RUN env| grep REACT_APP >> .env
RUN env| grep REACT_APP >> .env
will suffice
RUN command is launched "as-is", not through the shell. If you wish to use features like shell redirects you have to run it in the shell:
RUN ["/bin/bash", "-c", "env | grep \"REACT_APP\" >> .env"]
bash
, dash
, sh
- choose the shell you have in your image. Not every image has BASH inside.
You are could be getting the error because you may not have "REACT_APP" env set.
can you try it as follows,
ENV REACT_APP test
RUN env | grep "REACT_APP" >> .env
You cant use bash as alphine image only support sh
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.