前端vue打包成docker镜像启动(使用nginx服务)

 

 

首先创建一个nginx配置文件,这个文件后面会替换nginx镜像中的配置文件

default.conf

复制代码
server {
    listen       80;
    server_name  localhost; 

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
复制代码

 

创建Dockerfile文件

复制代码
FROM nginx

MAINTAINER “作者/维护者姓名”

RUN rm /etc/nginx/conf.d/default.conf

ADD default.conf /etc/nginx/conf.d/

COPY dist/ /usr/share/nginx/html/
复制代码

 

如果用docker-compose启动的话,

docker-compose.yml

复制代码
services:
  vue:
    build:
      context: .  #Dockerfile 所在目录
      dockerfile: Dockerfile 
    image: vue  #镜像名称
   # restart: unless-stopped
   # network_mode: "host"
    privileged: true
    container_name: vue
    volumes:
      - /logs:/logs
    ports:
      - 8080:80
复制代码

context: .  :这表示当前目录,也就是说Dockerfile和docker-compose在同一目录,

上面这个可以根据自己的来 ,我上面是映射了8080端口出来,所以访问是localhost:8080,docker内部之所以是80 ,是因为我们上面的nginx配置文件我们监听的是80端口

 

目录结构为

 

 

最后执行

docker-compose build
docker-compose up -d

 

启动成功后,访问 localhost:8080(这个是服务器内部访问,外部需要自己修改ip地址)

 

posted @   yvioo  阅读(1525)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-03-03 java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal报错处理
2020-03-03 java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
点击右上角即可分享
微信分享提示