简体   繁体   中英

Docker container only runs dashboard app on localhost:4200 and when localhost:8080 it display the nginx webpage

So I wrote this Dockerfile:

FROM node:13-alpine as build

WORKDIR /app

COPY package*.json /app/

RUN npm install -g ionic

RUN npm install

COPY ./ /app/

RUN npm run build

FROM nginx:alpine

RUN rm -rf /usr/share/nginx/html/*

COPY --from=build /app/dist/ /usr/share/nginx/html/

When it run the command npm run build it is going to create the Dist folder the second last line is going to remove the things from the folder nginx/html and than the last line is going to replace this folder with the files from the Dist folder, where is the Index.html .

when i run the code: docker build -t dashboard-app:v1. it creates the image

Than i run the code: docker run --name dashboard-app-container -d -p 8080:80 dashboard-app:v1

when i go to localhost:8080 it show " NGINX. If you see this page, the nginx web server is succesfully installed and working. Further coonfig. is required"

I dont know if my problem is that docker is not being able to replace the Dist folder and finding the index html or if is some port problem.

When i run it on localhost:4200 i can see the dashboard app.

Any sugestion???

Thank you in advance

It is certainly hard to know what is your Dist folder containing and what was copied over to the nginx/html/ location.

As long as you get a response on port 8080 , it means that nginx is running but is not able to find index.html page in the nginx/html/ folder.

What I suggest doing is to run your Docker image with the following command from a terminal. Notice, the -d is removed, you will be able to see the logs from the container:

docker run --name dashboard-app-container -p 8080:80 dashboard-app:v1

In another terminal connect to the image using the following command:

docker exec -it dashboard-app:v1 sh

This will open a shell to the container. You will have to navigate to /usr/share/nginx/html location and investigate its content. You will be able to see what was copied over from the Dist folder and adjust the Dockerfile aftewards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM