【发布时间】:2021-07-31 01:15:39
【问题描述】:
我正在尝试更改 docker 上 Vue.js 应用程序的默认端口。
我在官方文档中使用了这两个示例:https://vuejs.org/v2/cookbook/dockerize-vuejs-app.html
带有 http-server 的 Dockerfile:
FROM node:lts-alpine
# install simple http server for serving static content
RUN npm install -g http-server
# make the 'app' folder the current working directory
WORKDIR /app
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./
# install project dependencies
RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .
# build app for production with minification
RUN npm run build
EXPOSE 8080
CMD [ "http-server", "dist" ]
带有 nginx 服务器的 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 80
CMD ["nginx", "-g", "daemon off;"]
这是我的 docker-compose 文件:
version: "3.7"
services:
admclient:
build: ../food-order-frontend-admin
image: myapp/myapp:v1.0
container_name: myapp
ports:
- "6969:whateverIExposeInDockerFile"
这两个示例都有效,但仅在使用它们的默认端口 8080 和 80 时。使用非默认端口时,我在浏览器中收到以下错误:
crbug/1173575, non-JS module files deprecated
在控制台中没有任何用处。除非在 httpServer 上对应用程序进行 docker 记录:
Starting up http-server, serving dist
Available on:
http://127.0.0.1:8080
http://172.19.0.2:8080
显然,Dockerfiles 中的“公开任何端口”没有通过。 P.S:我不需要生产就绪的解决方案。所以我会寻求最快的解决方案。
【问题讨论】:
-
您是否正在做任何事情来更改应用程序正在侦听的端口(例如 Nginx
listen指令)?我们的 Docker 内部端口号有什么关系? -
嘿大卫,docker-internal 端口很重要,因为我在同一个 docker-compose 中有多个前端应用程序。因此不需要使用默认端口。使用 http-server,我认为除了 Dockerfile 之外不需要其他任何东西?使用 nginx ......好吧,我尝试了 10 个教程,例如这个家伙的解决方案,这似乎正是我需要的:youtube.com/watch?v=hqOW4TuN59M nginx 文件是:github.com/adhavpavan/ContainerizingApps/blob/master/vue/…
-
假设您有三个基于 Express 的组件,它们都侦听端口 3000。在容器之间您可以使用 Docker 网络并连接到
app1:3000、backend:3000等。在 Docker 之外,您可以将它们重新映射到不同的端口:app1设置3000:3000,backend6969:3000,等等。 -
但是第二个
ports:号码需要匹配应用程序正在监听的内容。更改 Docker 配置而不更改应用程序将导致此错误。设置EXPOSE几乎没有任何作用。
标签: docker vue.js docker-compose