Docker creates nginx image

  • Note: The image created by dockerfile is not used here, it is just used to play
  • First of all, you need to install docker in your system. I will not repeat the introduction here. You can read the previous article;
  • Then make a base image
    docker pull registry.cn-hangzhou.aliyuncs.com/centos-server/centos6:latest 
    docker images #View
    existing images
    #[root@localhost tmp]# docker images
    #REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
    #registry.cn-hangzhou .aliyuncs.com/centos-server/centos6 latest 1f7bf79ccbf3 8 months ago 260.9 MB #Change

    the REPOSITORY of the mirror
    docker tag 1f7bf79ccbf3 centos6 #Delete
    the previous mirror, the name is too long
    docker rmi registry.cn-hangzhou.aliyuncs.com/centos- server/centos6
  • Start a container with the base image
    docker run -itd --name nginx centos6 /bin/bash
  • into the container
    docker attach nginx
  • Install nginx and its dependencies in the container
    #download dependencies
    wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz
    wget www.zlib.net/fossils/zlib-1.2.8.tar.gz
    #Download the installation package
    wget http://nginx.org/download/nginx-1.10.3.tar.gz
    
    #install dependencies
    yum install -y gcc* c++ openssl openssl-devel cyrus-sasl-md5
    
    #Unzip all archives
    tar -zxvf pcre-8.39.tar.gz
    tar -zxvf zlib-1.2.8.tar.gz
    tar -zxvf nginx-1.10.3.tar.gz
    
    #install nginx
    cd nginx-1.10.3
    ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8
    make && make install
    
    #Configure environment variables
    vi /etc/profile
    export PATH="$PATH:/usr/local/nginx/sbin"
    source /etc/profile
    
    #Modify nginx configuration file
    vi /usr/local/nginx/conf/nginx.conf
    listen 8080
    #start nginx
    nginx
    #test
    curl localhost:8080
  • The installation is complete, exit the container
    exit #This exit method will also stop the docker container
  • Use the docker commit command to commit the image created for yourself
    docker commit -m 'Nginx' -a 'Centos-Nginx' 4188f4e5f136 registry.cn-hangzhou.aliyuncs.com/vlson/Centos-Nginx
  • Export the image created by yourself to the local
    docker save -o centos_nginx_docker_iso.tar registry.cn-hangzhou.aliyuncs.com/vlson/Centos-Nginx
  • Or upload the image created by yourself to the warehouse
    docker push registry.cn-hangzhou.aliyuncs.com/vlson/Centos-Nginx
  • Use docker load to import from the exported local file as an image
    docker load --input centos_nginx_docker_iso.tar

     

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325227104&siteId=291194637