mac docker打包nginx web应用

本文指导如何在Mac上安装Docker,并通过编写Dockerfile从CentOS基础镜像构建Nginx web应用。配置了Nginx配置文件以正确处理web应用的请求,并将应用打包输出到/web目录。最后,展示了如何打包Docker镜像及运行容器,将web应用暴露在7000端口。
摘要由CSDN通过智能技术生成

mac docker打包nginx web应用

本文使用docker打包nginx应用并运行;

安装docker

[Docker官网]](https://www.docker.com/)

1.编写DockerFile文件,在web项目中

#Nginx Dockerfile

FROM centos

# 下载阿里云的源替换官方的源
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

RUN ls /etc/yum.repos.d/

# 删除自带的源,避免去下国外的源
RUN rm -rf /etc/yum.repos.d/CentOS-Linux-AppStream.repo

# 删除自带的源,避免去下国外的源
RUN rm -rf /etc/yum.repos.d/CentOS-Linux-BaseOS.repo

RUN yum install -y nginx

RUN rm -rf /usr/share/nginx/html/*

# 复制nginx.conf
COPY nginx.conf /etc/nginx/nginx.conf

# 复制web应用,默认是 /web
COPY dist /usr/share/nginx/html/web

# 暴露端口
EXPOSE 7000 443

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

需要将打包输出路径设置为 /web;例:http://127.0.0.1/web/

2. 创建nginx.conf文件

# user  nginx;
worker_processes  1;

# pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

	error_log /var/log/nginx/server_error.log;

    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    
    server {
        listen 7000;
        server_name localhost;

        location / {
            root /usr/share/nginx/html;
            index index.html index.htm;
        }
        
        location /web {
            try_files $uri $uri/ /web/index.html?$query_string;
        }

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
    
    include servers/*;
}

3. 打包docker

# 打包镜像
docker build -t eladminv1.0 . 

# 运行docker 镜像
docker run -d -p 127.0.0.1:7000:7000 eladminv1.0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值