我有一个next.config.js
module.exports = {
.........
env: {
BASE_URL: 'http://xx.xx.xx.xx:8000',
},
............
};
现在我想在构建docker镜像时更改BASE_URL
我的Dockerfile
文件
FROM node:16-alpine3.14
WORKDIR /usr/app
COPY ./package.json ./
RUN yarn install
ENV BASE_URL=http://yy.yyy.yy.yy:80
# Copy all files
COPY ./ ./
RUN yarn build
因此,在Dockerfile中传递ENV BASE_URL=http://yy.yyy.yy.yy:80
将有助于更改next.config.js
中的BASE_URL: 'http://xx.xx.xx.xx:8000'
或者我可以改变BASE_URL
的方式
2条答案
按热度按时间j0pj023g1#
docker文件中的
ENV BASE_URL=http://yy.yyy.yy.yy:80
将设置一个环境变量BASE_URL
为其值,您需要读取该变量。iyzzxitl2#
创建了一个entrypoint.sh文件,并将以下脚本放入其中:
下面是我的Dockerfile引用entrypoint.sh文件
由next.config.js修改,按照以下方式定义环境变量: