I want to use other port like 3002 rather than 3000 in my react js app but I am not able to use it. can anyone please help me on this ?
Please note I don't want to change in the package.json to update the port -> "start" : "PORT=3002 react-scripts start"
I want to specifically change only in Dockerfile
Is there any way by which we can change in CMD to supply the PORT ?
FROM node:16.13.2
ARG DEFAULT_PORT 3002
ENV PORT ${DEFAULT_PORT}
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install
# add app
COPY . ./
#RUN export PORT=3002 -> with this one also not working
# start app
CMD ["npm", "start"]
CodePudding user response:
Please try below command.
CMD PORT=3002 npm start
It should change the port, don't use CMD ["PORT=3002", "npm", "start"]
CodePudding user response:
try to run
npx kill-port 3002
then start it again cause now that port is in use for some other project
CodePudding user response:
to use a manual port instead of a default port you can use this command
CMD PORT=3002 npm start
instead of npm start