Dockerfile自制Nginx

 

[root@jgharbor all-in-one]# ll
total 1032
-rwxrwxr-x. 1 root root     144 Feb 22 14:59 build-command.sh
drwxrwxr-x. 2 root root      24 Feb 22 15:00 code
-rw-rw-r--. 1 root root     292 Apr 14  2021 code.tar.gz
-rw-rw-r--. 1 root root     858 Feb 22 15:01 Dockerfile
-rw-rw-r--. 1 root root 1032630 Aug 14  2019 nginx-1.16.1.tar.gz
-rw-rw-r--. 1 root root    2681 Apr 14  2021 nginx.conf
-rw-rw-r--. 1 root root      65 Apr 14  2021 run_nginx.sh

build-command.sh:

#!/bin/bash
docker build -t 192.168.19.178/birkhoffxia/nginx-all-in-one:1.16.1 .
docker push 192.168.19.178/birkhoffxia/nginx-all-in-one:1.16.1

code:vim index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
        <title>马哥教育</title>
        </head>
        <body>
        <h1>测试页面</h1>
        </body>
        </html>

 

code.tar.gz:上面打包

Dockerfile:

#
#
#base image for m43 nginx
FROM centos:7.8.2003

maintainer  "Birkhoff 807722920@qq.com"

RUN yum install -y epel-release && yum install -y vim wget tree  lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop

#COPY nginx-1.16.1.tar.gz /usr/local/src/
ADD nginx-1.16.1.tar.gz /usr/local/src/

RUN cd /usr/local/src/nginx-1.16.1 && ./configure --prefix=/apps/nginx --with-http_sub_module && make && make install
RUN useradd nginx -u 2022
ADD nginx.conf /apps/nginx/conf/nginx.conf
ADD code.tar.gz /data/nginx/html
#ADD run_nginx.sh /apps/nginx/sbin/run_nginx.sh
#RUN chmod a+x /apps/nginx/sbin/run_nginx.sh
EXPOSE 80 443

#RUN useradd m43
#USER m43
#WORKDIR /opt
#run mkdir 123
#WORKDIR 123


#ENTRYPOINT ["/apps/nginx/sbin/run_nginx.sh"]

ENTRYPOINT ["/apps/nginx/sbin/nginx"]
CMD  ["-g","daemon off;"]

nginx-1.16.1.tar.gz
nginx.conf:

user  nginx;
worker_processes  auto;

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

#pid        logs/nginx.pid;
#daemon off;

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;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /data/nginx/html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

run_nginx.sh:

#!/bin/bash
echo "1.1.1.1" >> /etc/hosts

/apps/nginx/sbin/nginx

构建上传镜像仓库:


[root@jgharbor all-in-one]# chmod a+x build-command.sh
[root@jgharbor all-in-one]# ./build-command.sh
Sending build context to Docker daemon 1.044MB
Step 1/11 : FROM centos:7.8.2003
---> afb6fca791e0
Step 2/11 : maintainer "Birkhoff 807722920@qq.com"
---> Running in 20f25cf50b0c
Removing intermediate container 20f25cf50b0c
---> bb473c971150
Step 3/11 : RUN yum install -y epel-release && yum install -y vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop
---> Running in d86cd9501292
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution


Dependencies Resolved


================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
epel-release noarch 7-11 extras 15 k


Transaction Summary
================================================================================
Install 1 Package


Total download size: 15 k
Installed size: 24 k
Downloading packages

Omiit:.......编译安装部分省略
make
[1]: Leaving directory `/usr/local/src/nginx-1.16.1' Removing intermediate container 4996f1be67f0 ---> 844f47c6ab5a Step 6/11 : RUN useradd nginx -u 2022 ---> Running in 4ad8133ba24d Removing intermediate container 4ad8133ba24d ---> 7c73bbc6ed89 Step 7/11 : ADD nginx.conf /apps/nginx/conf/nginx.conf ---> dd28bf8dd39e Step 8/11 : ADD code.tar.gz /data/nginx/html ---> fd1d0bc75f20 Step 9/11 : EXPOSE 80 443 ---> Running in 226a48ecdb92 Removing intermediate container 226a48ecdb92 ---> a64f6cb66bad Step 10/11 : ENTRYPOINT ["/apps/nginx/sbin/nginx"] ---> Running in 73917dfe14f2 Removing intermediate container 73917dfe14f2 ---> 55ad86aeb900 Step 11/11 : CMD ["-g","daemon off;"] ---> Running in 71e38ffd6aa0 Removing intermediate container 71e38ffd6aa0 ---> 922a4782b49d Successfully built 922a4782b49d Successfully tagged 192.168.19.178/birkhoffxia/nginx-all-in-one:1.16.1 The push refers to repository [192.168.19.178/birkhoffxia/nginx-all-in-one] ab75956f51d2: Pushed e10648cbbc97: Pushed eef1565f126a: Pushed 71d8340b272a: Pushed 16df317b56f8: Pushed ba4ccc58e22f: Pushed fb82b029bea0: Mounted from birkhoffxia/tomcat-xks 1.16.1: digest: sha256:48fd54a34e9349492b285d42f22a0fcb076fcde3f9cc66cc2af6f832abf4a95d size: 1787

 

 

 

 
posted @ 2023-02-22 15:38  しみずよしだ  阅读(48)  评论(0)    收藏  举报