基于Docker搭建vue前端项目

新建一个vue项目,或clone下仓库上的项目在你的工作目录vue

npm install && npm run build

打包生成vue的一个dist


image.png

基于nginx镜像生成一个vue前端项目的容器
映射项目文件地址:./web/dist:/usr/share/nginx/html/
并映射nginx配置80端口配置:./vue.conf:/etc/nginx/conf.d/default.conf
vue.conf配置为:

server {
    listen       80;
    server_name  localhost;
    access_log  /var/log/nginx/host.access.log  main;
    error_log  /var/log/nginx/error.log  error;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

docker-compose.yml

version: "3"
services:
  vue:
    image: nginx:latest
    container_name: vue
    hostname: vue
    ports:
      - "4000:80"
    volumes:
      - ./web/dist:/usr/share/nginx/html/  #创建项目根目录
      - ./vue.conf:/etc/nginx/conf.d/default.conf
    restart: always

执行命令docker-compose up -d,然后可以访问前端静态项目了。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容