基于本指南:
https://shekhargulati.com/2019/01/18/dockerizing-a-vue-js-application/
我已经创建了一个示例VueJS应用并创建了一个docker映像:
axios.get("user")
基于以下Dockerfile:
docker build -t myapp .
接下来,我使用以下命令运行一个docker容器:
# base image
FROM node:10.15.0
# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install -g @vue/cli
# start app
CMD ["npm", "run", "serve"]
并获得以下(成功的)输出:
docker run -it -v ${PWD}:/usr/src/app -v /usr/src/app/node_modules -p 5000:5000 myapp
然后,我尝试通过http://localhost:5000/上的浏览器访问该应用程序,但出现一个连接已重置错误。
我还尝试使用以下方法检查正在运行的容器上的端口信息:
DONE Compiled successfully in 4644ms 4:05:10 PM
No type errors found
No lint errors found
Version: typescript 3.4.3, tslint 5.15.0
Time: 4235ms
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.
但这基本上可以确认我传递给run命令的端口信息。
关于如何从主机上的浏览器访问容器中的VueJS应用程序的任何建议?