Production docker service of the mirror

Mirroring

Manual production yum mirror source nginx

1, into the container

$ docker run -it -p 8802:80

2, container operations

$ yum install wget -y

$ rm -rf ./etc/yum.repos.d/*
 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
$ yum install -y vim wget pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop

$ yum install nginx –y
$ vim /etc/nginx/nginx.conf
daemon off;
      


server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }
# 添加location      
  location /pansn {
             root /data/nginx/html;
             index index.html;
}



$ mkdir -p /data/nginx/html/pansn
$ echo "test linux37" > /data/nginx/html/pansn/index.html
$ mv 1.jpg /data/nginx/html/pansn



3、创建镜像
重开一个终端窗口创建镜像

$ docker commit -a "[email protected]" -m "nginx yum v1" --change="EXPOSE 80 443" 373b8f018f4c docker.io/linux37/centos-nginx:v1

$ docker commit -a "[email protected]" -m "nginx yum  v1" --change="EXPOSE 80 443" 05b7e99cf4b8 www.pansn.cn/linux37/centos-nginx:v1

4、启动镜像并传递命令nginx启动命令
$ docker run -d -it -p 82:80 www.pansn.cn/linux37/centos-nginx:v1 nginx 
$ ss -ntl  #确定82端口是否开启成功

verification

Finally, the backup image to another terminal authentication guide

$ docker save www.pansn.cn/linux37/centos-nginx:v1 > /opt/nginx-v1

$ ll /opt

-rw-r--r--  1 root root 259636224 Sep 13 17:38 nginx-v1

root@docker-node1:~# scp /opt/nginx-v1 192.168.7.102:/opt
[email protected]'s password: 
nginx-v1                                                                                       100%  428MB 105.7MB/s   00:04    
root@docker-node1:~# 

 导入镜像并启动
root@docker-node2:/opt# docker load -i nginx-v1 
877b494a9f30: Loading layer [==================================================>]  209.6MB/209.6MB
57ea5df43423: Loading layer [==================================================>]  239.4MB/239.4MB
Loaded image: www.pansn.cn/linux37/centos-nginx:v1
root@docker-node2:/opt# docker run -it -d www.pansn.cn/linux37/centos-nginx:v1 
aaaf2d83949fccf833b26dc40310bbba7a747b7578d439e03bd795c7de21aa38

映射端口
$ docker run -it -d -p 80:80 www.pansn.cn/linux37/centos-nginx:v1 nginx

再次验证即可

DockerFile production version of nginx yum mirror

DockerFile can be said that the script of which may be interpreted Docker program, a command is DockerFile bar composition, each command corresponding to a command linux following, these DockerFile Docker program instructions and then translated into a real linux commands, which have own writing systems and command support, the program reads DockerFile Docker Docker and generate the mirror according to the instruction, compared to manual to mirror the way, DockerFile more intuitive display mirroring is how to produce, with the DockerFile, when there is an additional late when needs, just add or modify the response before DockerFile command to regenerate a new Docke mirror, to avoid the trouble of repeated manual mirrored

Official dockerfile: https: //github.com/nginxinc/docker-nginx/blob/master/stable/buster/Dockerfile
environment to prepare:

nginx软件:
nginx-1.16.1.tar.gz  


nginx.conf


user  nginx;
daemon off;
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

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

        location /app {
         root /data/nginx/html/linux37;
          index index.html;
        }


$ mkdir /data/nginx/html/linux37/apps -pv
$ vim /data/nginx/html/linux37/apps/index.html
app index.html

$ useradd nginx -u 2019

Download base image Centos:

$ docker pull centos

Create a mirror directory:

$ mkdir  /opt/dockerfile/{web/{nginx,tomcat,jdk,apache},system/{centos,ubuntu,redhat}} -pv

Construction of Nginx Mirror

$ cd /opt/dockerfile/system/centos/

$ vim Dockerfile

# Nginx centos

FROM centos:latest

MAINTAINER pansn [email protected]

ENV PASSWD 123456
ENV USER nginx

RUN cd /opt && touch linux37.txt

#执行命令,将编译nginx的步骤执行一遍
RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop

ADD nginx-1.16.1.tar.gz /usr/local/src
RUN cd /usr/local/src/nginx-1.16.1 && ./configure --prefix=/apps/nginx && make && make install && ln -sv /apps/nginx/sbin/nginx /usr/bin

RUN useradd nginx -u 2019 && mkdir /data/nginx/html/linux37 -pv

ADD nginx.conf /apps/nginx/conf/nginx.conf
ADD app.tar.gz /data/nginx/html/linux37

RUN chown -R  nginx.nginx /data/nginx/ /apps/nginx

EXPOSE 80 443

CMD ["nginx"]
~ 

执行构建镜像:

 $ docker build -t centos-nginx:v1 .           #后面有个点表示在本目录执行Dockerfile

验证:
···
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nginx latest 6095d33ccf33 2 hours ago 543MB

$ docker run -it --rm -p 80:80 centos-nginx:latest
···

Guess you like

Origin www.cnblogs.com/pansn/p/11524873.html