Docker运行Vue项目

    本人非前端,只是为了部署才。Dockfile的内容主要来源于Vue官方:https://cn.vuejs.org/v2/cookbook/dockerize-vuejs-app.html

    直接上Dockerfile吧,和官方的几乎一样,但细节上面做了配置,更贴近实际使用。详情请看Dockerfile内容:

FROM node:lts-alpine
# 如果你在国内,这行配置很有必要,不然打包会非常非常慢,原因嘛,都懂。
RUN npm config set registry https://registry.npm.taobao.org
# 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:prod

EXPOSE 9000
# 加入端口自定义配置,避免与其他K8S容器端口冲突
CMD [ "http-server","-p","9000", "dist" ]

    构建Docker镜像:

docker build -t registry.cn-hangzhou.aliyuncs.com/xxx/xxx .

    测试镜像可用性:

docker run -p 80:9000 --rm registry.cn-hangzhou.aliyuncs.com/xxx/xxx

420a852bc4196a70ca4d284ddedbfb93566.jpg

转载于:https://my.oschina.net/vright/blog/3093196

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值