I have a next.config.js
module.exports = {
.........
env: {
BASE_URL: 'http://xx.xx.xx.xx:8000',
},
............
};
If I want to change the BASE_URL while building docker image I can do
my Dockerfile file
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
SO ENV BASE_URL=http://yy.yyy.yy.yy:80 in your docker file will set an environment variable BASE_URL to it's value, you need to read it for that variable.
//next.config.js
module.exports = {
.........
env: {
BASE_URL: process.env.BASE_URL || 'http://xx.xx.xx.xx:8000', //read the value from env id empty use default value.
},
............
};
But how can I make this image more generic, So that while running the service in dockercompose i can pass the BASE_URL
Is that possible.
Else for every different BASE_URL, i have to create different images.