docker创建nginx镜像

  • 注意:此处不是用的dockerfile创建的镜像,只是用来搞一搞
  • 首先你的系统里面要安装docker,这里就不重复介绍了,可以看之前的文章;
  • 然后再搞一个基础镜像
    docker pull registry.cn-hangzhou.aliyuncs.com/centos-server/centos6:latest
    docker 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

    #改一下镜像的REPOSITORY
    docker tag 1f7bf79ccbf3 centos6
    #删除之前的镜像,名字太长
    docker rmi registry.cn-hangzhou.aliyuncs.com/centos-server/centos6
  • 用基础镜像启动一个容器
    docker run -itd --name nginx centos6 /bin/bash
  • 进入容器
    docker attach nginx
  • 在容器中安装nginx以及其依赖
    #下载依赖
    wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz
    wget www.zlib.net/fossils/zlib-1.2.8.tar.gz
    #下载安装包
    wget http://nginx.org/download/nginx-1.10.3.tar.gz
    
    #安装依赖
    yum install -y gcc* c++ openssl openssl-devel cyrus-sasl-md5
    
    #解压所有压缩包
    tar -zxvf pcre-8.39.tar.gz
    tar -zxvf zlib-1.2.8.tar.gz
    tar -zxvf nginx-1.10.3.tar.gz
    
    #安装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
    
    #配置环境变量
    vi /etc/profile
    export PATH="$PATH:/usr/local/nginx/sbin"
    source /etc/profile
    
    #修改nginx配置文件
    vi /usr/local/nginx/conf/nginx.conf
    listen 8080
    #启动nginx
    nginx
    #测试
    curl localhost:8080
  • 安装完成,退出容器
    exit   #这种退出方式也会停止docker容器
  • 使用docker commit命令来提交为自己创建的镜像
    docker commit -m 'Nginx' -a 'Centos-Nginx' 4188f4e5f136 registry.cn-hangzhou.aliyuncs.com/vlson/Centos-Nginx
  • 将自己创建的镜像导出到本地
    docker save -o centos_nginx_docker_iso.tar registry.cn-hangzhou.aliyuncs.com/vlson/Centos-Nginx
  • 或将自己创建的镜像上传到仓库
    docker push registry.cn-hangzhou.aliyuncs.com/vlson/Centos-Nginx
  • 使用docker load从导出的本地文件再导入为镜像
    docker load --input centos_nginx_docker_iso.tar

猜你喜欢

转载自www.cnblogs.com/wxdblog/p/8984108.html