I am using Nodejs with angular app. I deploy angular to my docker desktop. It is running but when I want access from my pc using localhost from PC browser , it does not connect..
Here is docker image running
Here is Dockerfile code
FROM node:16.13.1 as build
WORKDIR /app
COPY package.json /app
COPY . .
RUN npm install
RUN npm run build --prod
RUN ls -la dist
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 4200
When I want access using http://localhost:4200/ from my pc , it is not connecting.
Please help to find out the problem..
2
Answers
nginx:alpine
expose on port 80.port 4200 is used for development when you run
npm start
orng serve
.EXPOSE 4200 does nothing and is in this case misleading. You use EXPOSE to document what port the image listens on. As Antoine says, nginx listens on port 80, so if you want an EXPOSE statement, it should be
EXPOSE 80
.Remove the EXPOSE statement since it’s misleading
When you run your container, you can then map port 80 in the container to port 4200 on your machine like this
You’ll then be able to load your app by going to http://localhost:4200/