我正在嘗試使用以下命令運行我的 docker 映像,但我無法連接到我的 web VueJS 專案:
docker run -it -p 8080:8080 --rm dependency_check_front
在我的除錯中,我有:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/04/21 10:26:55 [notice] 1#1: using the "epoll" event method
2022/04/21 10:26:55 [notice] 1#1: nginx/1.20.2
2022/04/21 10:26:55 [notice] 1#1: built by gcc 10.3.1 20210424 (Alpine 10.3.1_git20210424)
2022/04/21 10:26:55 [notice] 1#1: OS: Linux 5.10.102.1-microsoft-standard-WSL2
2022/04/21 10:26:55 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/04/21 10:26:55 [notice] 1#1: start worker processes
2022/04/21 10:26:55 [notice] 1#1: start worker process 33
2022/04/21 10:26:55 [notice] 1#1: start worker process 34
2022/04/21 10:26:55 [notice] 1#1: start worker process 35
2022/04/21 10:26:55 [notice] 1#1: start worker process 36
我的 VueJS 專案的 dockerfile :
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
當我嘗試在我的網站上連接時,出現此錯誤:

uj5u.com熱心網友回復:
該EXPOSE宣告實際上并沒有做任何事情。它主要是一些關于您的容器偵聽的埠的檔案。在您的情況下,這是不正確的,因為 Nginx 默認偵聽埠 80。
運行容器時,應將埠 80 映射到要在主機上使用的埠。IE
docker run -it -p 8080:80 --rm dependency_check_front
現在您應該可以通過 http://localhost:8080/ 訪問您的應用了
您應該洗掉 Dockerfile 中的 EXPOSE 陳述句,因為它會使以后查看您的 Dockerfile 的任何人感到困惑。
如果你真的想讓 Nginx 監聽 8080 埠,你必須配置 Nginx 來做到這一點,但 IMO 不值得。讓它監聽 80 埠。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460314.html
