Docker Can';t访问固定的Vue';主机上的s localhost:8080(尽管暴露了ing端口)

Docker Can';t访问固定的Vue';主机上的s localhost:8080(尽管暴露了ing端口),docker,vue.js,Docker,Vue.js,对接应用程序后,我无法再访问localhost:8080上的Vue应用程序 我有一个Dockerfile,内容如下: # Base the image off of the NodeJS image FROM node # Set the working directory to be the HOME directory WORKDIR /root # Install NPM dependencies early in the build process COPY ./pack

对接应用程序后,我无法再访问
localhost:8080
上的Vue应用程序

我有一个
Dockerfile
,内容如下:

 # Base the image off of the NodeJS image
 FROM node

 # Set the working directory to be the HOME directory
 WORKDIR /root

 # Install NPM dependencies early in the build process
 COPY ./package.json /root
 COPY ./package-lock.json /root
 RUN npm install

 # Specify what port will be available - necessary for VPC network
 EXPOSE 8080

 # Copy our application files to the image
 COPY ./.browserslistrc /root
 COPY ./.eslintrc.js /root
 COPY ./.env /root
 COPY ./babel.config.js /root
 COPY ./README.md /root
 COPY ./vue.config.js /root
 COPY ./public /root/public
 COPY ./src /root/src

 # Start the container running our Node app
 CMD ["npm", "run", "serve"]
(在停靠之前,
npm run serve
允许我通过web浏览器访问Vue应用程序。)

然后我运行PS命令
docker build

PS C:\Users\User\mealSocial-dev> docker build -t finalvue app
Sending build context to Docker daemon  126.8MB
Step 1/15 : FROM node
 ---> 448d0873ea84

[...]

Step 15/15 : CMD ["npm", "run", "serve", "--port", "\"8080\""]
 ---> Running in c4840f98e5dc
Removing intermediate container c4840f98e5dc
 ---> 904928fa859c
Successfully built 904928fa859c
Successfully tagged finalvue:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
…然后
docker运行-p8080:8080

PS C:\Users\User\mealSocial-dev> docker run -p 8080:8080 finalvue

> meal-app@0.1.0 serve /root
> vue-cli-service serve

 INFO  Starting development server...
<s> [webpack.Progress] 0% compiling

[...]

DONE Compiled successfully in 8147ms11:39:59 AM
<s> [webpack.Progress] 100%    
App running at:    
- Local: http://localhost:8080/    
It seems you are running Vue CLI inside a container.    
Access the dev server via http://localhost:<your container's external mapped port>/    
Note that the development build is not optimized.   
To create a production build, run npm run build.
PS C:\Users\User\mealSocial dev>docker run-p8080:8080 finalvue
>餐-app@0.1.0上菜/根
>vue cli服务
正在启动开发服务器。。。
[webpack.Progress]0%正在编译
[...]
在8147ms11:39:59 AM成功编译完成
[网页进度]100%
应用程序运行于:
-本地:http://localhost:8080/    
您似乎正在容器中运行Vue CLI。
通过访问dev服务器http://localhost:/
,我发现
这个页面不工作。localhost未发送任何数据。ERR\u EMPTY\u响应


当我运行
docker run
时,我正在
EXPOSE
Dockerfile
中打开端口,并添加
-p 8080:8080
标记。我遗漏了什么?

评论部分:

将主机0.0.0.0添加到npm运行服务中


主机:0.0.0.0
添加到配置(
/vue.config.js

您可以粘贴
主机
文件的内容吗。看起来您正在使用windows计算机。在这方面,它通常位于这里-
c:\windows\system32\drivers\etc\hosts
还要确保您正在点击
http://localhost:8080
而非
https://localhost:8080
(http和https是区别)在浏览器上。是否可以将
--host 0.0.0.0
添加到
npm run serve
host='0.0.0'
到您的配置中,然后重试?@invad0r-就是这样!非常感谢你!在
/vue.config.js
中,我将
host:localhost
更改为
host:0.0.0