I need to pass the environment variable in my Dockerfile like below. May i know the efficient way to do this. I tried using build args
docker build --build-arg myIP=123 --rm -t react_2811_1154 .
but it didnt work.
Here is my Dockerfile
ARG myIP
FROM node:11
ENV myIP1 $myIP
ENV REACT_APP_MOCK_API_URL=http://${myIP1}:8080/API
ENV REACT_APP_MOCK_API_URL_AUTH=http://${myIP1}:8080/API/AUTH
ENV REACT_APP_MOCK_API_URL_PRESENTATION=http://${myIP1}:8080/API/PRESENTATION
# set working directory
RUN mkdir /usr/src/app/
WORKDIR /usr/src/app/
COPY . /usr/src/app/.
RUN npm install
#RUN npm start
CMD ["npm", "start" ]
So when i run my docker container i believe i dont want to send any environment variable to it.
Please advise.
I ran your Dockerfile and myIP
is indeed empty when I run env
inside of the container.
To fix it, try putting the ARG
line AFTER the FROM
line.
So,
FROM node:11
ARG myIP
ENV myIP1 $myIP
ENV REACT_APP_MOCK_API_URL=http://${myIP1}:8080/API
ENV REACT_APP_MOCK_API_URL_AUTH=http://${myIP1}:8080/API/AUTH
ENV REACT_APP_MOCK_API_URL_PRESENTATION=http://${myIP1}:8080/API/PRESENTATION
Building using this Dockerfile, I was able to set myIP
.
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.