有条件的 npm 在 Dockerfile 中安装 ARG
Conditional npm install ARG in Dockerfile
我正在尝试根据参数从 GitHub 安装节点模块包。我试过但是我不完全理解这个解决方案。执行没有错误,但我确定它没有安装包。我 运行 在部署之前本地容器并获取模块未找到错误
Dokerfile
就像 that.Can 是否可以将每个命令保持在一个新行中?
FROM node:10
ENV HOME /usr/src/reach-live-api
ARG siteval
RUN mkdir -p $HOME
RUN mkdir -p /root/.ssh
WORKDIR $HOME
COPY ./keys/reachlive_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "Host bitbucket.org\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
COPY . $HOME
RUN npm install --silent --production
RUN if [ "$siteval" = "prod" ]; then \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase-prod.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal-prod.git" \
else \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal.git"; \
fi
RUN npm prune --production
RUN rm -fr .npm
RUN rm -fr /root/.ssh
RUN rm -fr keys
CMD ["npm", "start"]
我使用下面的命令来构建
docker build -t gcr.io/reachlive-123/api:25Apr2020 . --build-arg siteval=dev
不胜感激
原来问题出在
RUN if [ "$siteval" = "prod" ]; then \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase-prod.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal-prod.git" \
else \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal.git"; \
fi
我已将其更改为并且有效
RUN if [ "$arg" = "prod" ]; then \
npm install reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git \
reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase-prod.git \
reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal-prod.git ; \
else \
npm install reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch.git \
reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase.git \
reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal.git; \
fi
感谢 Pavittar Singh 帮助我们解决这个问题!
我正在尝试根据参数从 GitHub 安装节点模块包。我试过但是我不完全理解这个解决方案。执行没有错误,但我确定它没有安装包。我 运行 在部署之前本地容器并获取模块未找到错误
Dokerfile
就像 that.Can 是否可以将每个命令保持在一个新行中?
FROM node:10
ENV HOME /usr/src/reach-live-api
ARG siteval
RUN mkdir -p $HOME
RUN mkdir -p /root/.ssh
WORKDIR $HOME
COPY ./keys/reachlive_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "Host bitbucket.org\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
COPY . $HOME
RUN npm install --silent --production
RUN if [ "$siteval" = "prod" ]; then \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase-prod.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal-prod.git" \
else \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal.git"; \
fi
RUN npm prune --production
RUN rm -fr .npm
RUN rm -fr /root/.ssh
RUN rm -fr keys
CMD ["npm", "start"]
我使用下面的命令来构建
docker build -t gcr.io/reachlive-123/api:25Apr2020 . --build-arg siteval=dev
不胜感激
原来问题出在
RUN if [ "$siteval" = "prod" ]; then \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase-prod.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal-prod.git" \
else \
RUN npm install "reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch.git" \
RUN npm install "reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase.git" \
RUN npm install "reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal.git"; \
fi
我已将其更改为并且有效
RUN if [ "$arg" = "prod" ]; then \
npm install reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git \
reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase-prod.git \
reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal-prod.git ; \
else \
npm install reach-live-elasticsearch@git+https://github.com/lalitmohan001/reach-live-elasticsearch.git \
reach-live-firebase@git+https://github.com/lalitmohan001/reach-live-firebase.git \
reach-live-paypal@git+https://github.com/lalitmohan001/reach-live-paypal.git; \
fi
感谢 Pavittar Singh 帮助我们解决这个问题!