用docker打包一个前端项目

思路:将dist包 打包成一个镜像(要不打出的镜像特别大)

Dockerfile:如下

FROM nginx:latest

COPY dist /auth-center

WORKDIR auth-center

COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

# 构建镜像 docker build -t auth-center:v1.0 .
# 运行镜像 docker run -itd --name myproject -p 5289:80 auth-center:v1.0
nginx.conf:如下
server {
listen 80;
server_name localhost;

location / {
  root /auth-center; # 打包的路径
  index index.html index.htm;
  try_files $uri $uri/ /index.html; # 防止重刷新返回404
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
  root /usr/share/nginx/html;
}
}
 
 
posted @ 2023-02-10 15:42  国服第一李师师  阅读(243)  评论(0编辑  收藏  举报