docker制作nginx带upsync模块镜像

FROM alpine:latest
ADD nginx-1.21.6.tar.gz /home/
ADD pcre-8.44.tar.gz /home/    
ADD openssl-1.0.2q.tar.gz /home/
ADD zlib.tar.gz /home/
ADD v2.1.3.tar.gz /home/
RUN echo http://mirrors.aliyun.com/alpine/v3.10/main/ > /etc/apk/repositories && \
    echo http://mirrors.aliyun.com/alpine/v3.10/community/ >> /etc/apk/repositories
RUN apk update && apk upgrade && \
    apk add  gcc g++ make && \
    addgroup -S nginx && \
    adduser -DHS -s /sbin/nologin -G nginx nginx && \
    cd /home/nginx-1.21.6 && \
    ./configure --prefix=/usr/local/nginx --with-pcre=/home/pcre-8.44 --with-openssl=/home/openssl-1.0.2q --with-zlib=/home/zlib-1.3 --without-http_gzip_module --add-module=/home/nginx-upsync-module-2.1.3 && \
    make && make install && \
    ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ && \
    rm -rf /home/nginx-1.21.6 && \
    rm -rf /home/pcre-8.44 && \
	rm -rf /home/openssl-1.0.2q && \
	rm -rf /home/zlib-1.3 && \
	rm -rf /home/nginx-upsync-module-2.1.3 && \
    apk del gcc && \
    apk del g++ && \
    rm -rf /apk/repositories && \
    mkdir -p /usr/local/nginx/conf/vhost/
EXPOSE 80
CMD ["/usr/sbin/nginx","-g","daemon off;"]

docker build -t nginx:alpine .

docker run -d --name vcupsync -p 88:80 nginx:alpine

docker制作nginx带upsync模块镜像_第1张图片

最好是让自己的网络可以访问外网这样apk update && apk upgrade时基本不会出现网络问题导致失败

这种就是网络问题导致的失败

docker制作nginx带upsync模块镜像_第2张图片

所需资源包https://download.csdn.net/download/qq_30920479/88750435

上传到nexus私库

docker tag nginx:alpine 192.168.99.182:8082/nginx:alpine


docker login -u username -p password 192.168.99.182:8082

docker push 192.168.99.182:8082/nginx:alpine

由于是简化版alpine 

docker images

docker exec -it 34738f7c2627 /bin/sh

docker-compose部署测试

nginx:
  image: 192.168.99.182:8082/nginx:alpine
  container_name: nginx
  volumes:
    - /home/data/nginx/conf:/usr/local/nginx/conf
    - /home/data/nginx/logs:/var/log/nginx
    - /home/data/nginx/html:/usr/local/nginx/html
    - /home/data/nginx/proxy_temp:/usr/local/nginx/proxy_temp
  ports:
    - 80:80
    - 443:443
    - 5885:5885


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    
	
	upstream swoole_test {
		#ip_hash;
        server 192.168.99.203:8060;
        #server 192.168.100.27:80;
        #server 192.168.100.29:80;
        upsync 192.168.99.115:8500/v1/kv/upstreams/swoole_test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
        
        upsync_dump_path /usr/local/nginx/conf/vhost/swoole_test.conf;
        #include /www/server/nginx/conf/vhost/servers_skuprice.conf;
     }
     
	server
    {
         listen 5885;
         #server_name 10.10.1.57;
		 #listen       80;
        server_name  localhost;
         location / {
          proxy_pass         http://swoole_test; 
          proxy_set_header   Host             $host; 
          proxy_set_header   X-Real-IP        $remote_addr; 
          proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 
          # 显示具体负载的机器的ip,X-Route-Ip随便命名
          add_header X-Route-Ip $upstream_addr;
	        add_header X-Route-Status $upstream_status;
            # 文件不能下载 设置缓存
            proxy_buffering on;
            proxy_buffer_size 512k;
            proxy_buffers 2 512k;
            proxy_busy_buffers_size 512k;
            proxy_temp_path /usr/local/nginx/proxy_temp 1 2;
            proxy_max_temp_file_size 100M;
            proxy_temp_file_write_size 512k;
            # 文件不能下载结束
        }
    }

}

你可能感兴趣的:(docker,nginx,容器)