I am running my react app on nginx server via Docker.
Without docker and nginx, my app runs fine on localhost:3000/app path.
But After adding Dockerfile and nginx, it is redirecting the path to localhost/app, ignoring the port.
Dockerfile
FROM node:16 as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
RUN rm -rf /etc/nginx/conf.d/*
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html/app
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
server {
listen 80;
server_name localhost;
location /app{
alias /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
}
Below is the command, I am running for docker app
docker run -p 3000:80 app
I have tried multiple approaches for nginx.conf file and Dockerfile.
But nothing seems to work.
I am new to react and dockerfile, I feel that there is just a small piece of the puzzle which I am missing.
Any help will be appreciated.