docker+nginx部署前端的dist

docker+nginx部署前端的dist

1、编写Dockerfile:
# 设置基础镜像
FROM nginx:alpine
# 将dist文件中的内容复制到 /app/dist 这个目录下面
COPY dist/  /app/dist
#用本地的 default.conf 配置来替换nginx镜像里的默认配置
COPY default.conf /etc/nginx/conf.d/default.conf
2、编写nginx配置文件default.conf:
upstream backendapi {
    server backend-api:9527;
}

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   /app/dist;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }
  
    error_page   500 502 503 504  /50x.html;
    location /api/ {  # 匹配api接口,进行转发配置
        rewrite  /api/(.*)  /$1  break;
        proxy_pass http://backendapi;  #转发到后端接口
    }
3、制作镜像:
# 把Dockerfile、default.conf、dist放在同级目录下
# 创建容器
docker build -t frontend/web .
# 给容器打上标签
docker tag frontend/web:latest harbor/frontend/web:latest
# 登录harbor容器仓库
docker login harbor
# 输入账号密码
# 推送打上标签的容器到harbor仓库
docker push harbor/frontend/web:latest  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值