• 基于正在运行中的容器制作镜像


    基于正在运行中的容器制作

    docker commit --help
    Usage:	docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
    Create a new image from a container's changes
    Options:
      -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
      -c, --change list      Apply Dockerfile instruction to the created image
      #-c 可将Dockerfile指令应用于创建的映像
      -m, --message string   Commit message
      -p, --pause            Pause container during commit (default true)
    

    docker yum部署nginx

    #下载官方基础镜像
    docker pull centos:7.7.1908
    #创建并进入容器
    docker run -it -p 80:80 centos:7.7.1908 bash
    
    
    #更改yum源
    wget -O /etc/yum.repo.d/CentOS-Base.repo http://mirroros.aliyun.com/repo/Centos-7.repo
    yum install -y epel-release 
    #安装常用工具
    yum install -y net-tools vim wget pcre pcre-devel zlib zlib-devel openssl openssl-devel  iproute iotop
    #安装nginx和常用工具
    yum install -y nginx
    #修改配置文件,改为前台运行;主配置段添加配置
    daemon off;
    #编写页面,无法保存;需要删除原链接文件
    cd /usr/share/nginx/html
    echo "<h1>hello docker</h1>" > index.html
    #启动nginx
    nginx -t
    nginx
    #测试访问
    curl 192.168.121.81
    <h1>hello docker</h1>
    
    
    
    #在宿主机操作,注意不要关闭docker终端;
    #提交为镜像
    docker commit -a "gms 952726682@qq.com" -m "nginx 1.16.1" d47d3370e7b2 centos-nginx:v1.16.1
    sha256:1053a863db3c7b5f655af22a3592cd35bf68efe64485deb280a976c449f4be95
    #查看images
    docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    centos-nginx        v1.16.1             1053a863db3c        11 seconds ago      429MB
    #测试镜像
    docker run -it -p 8880:80 centos-nginx:v1.16.1 nginx 
    #测试镜像
    curl 192.168.121.81:8880
    <h1>hello docker</h1>
    
    
    
    #修改配置文件,去除
    daemon off;
    #再次提交为镜像
    docker commit -a "gms 952726682@qq.com" -m "nginx 1.16.1" [CONTAINER ID] centos-nginx-v2:v1.16.1
    #如果未配置后台启动,也可进行命令传参数
    docker run -it -p 8881:80 centos-nginx-v2:v1.16.1 nginx "-g daemon off"
    

    docker 编译部署nginx

    #下载官方基础镜像
    docker pull centos:7.7.1908
    #创建并进入容器
    docker run -it -p 80:80 centos:7.7.1908 bash
    
    
    #更改yum源
    wget -O /etc/yum.repo.d/CentOS-Base.repo http://mirroros.aliyun.com/repo/Centos-7.repo
    yum install -y epel-release 
    #安装常用工具
    yum install -y net-tools vim wget pcre pcre-devel zlib zlib-devel openssl openssl-devel  iproute iotop
    #下载nginx
    wget -O /usr/local/src http://nginx.org/download/nginx-1.16.1.tar.gz
    #解压
    tar xvf nginx-1.16.1.tar.gz && cd nginx-1.16.1
    #安装
    ./configure --prefix=/usr/local/nginx
    make && make install
    #修改配置文件
    vim /usr/local/nginx/nginx.config
    #编写页面,无法保存;需要删除原链接文件
    cd /usr/share/nginx/html
    echo "<h1>hello docker make nginx</h1>" > index.html
    #制作软连接
    ln -sv /usr/local/nginx/sbin/nginx /usr/bin/
    #提交为镜像
    docker commit -a "gms 952726682@qq.com" -m "nginx-make 1.16.1" [CONTAINER ID] centos-nginx:v2
    #制作软连接
    docker run -it -p 8803:80 centos-nginx:v2 nginx "-g daemon off"
    
    
    #skip制作软连接
    #再次提交为镜像
    docker commit -a "gms 952726682@qq.com" -m "nginx-make 1.16.1" [CONTAINER ID] centos-nginx:v1
    #若未制作软连接,则在docker run是需要写绝对路径
    docker run -it -p 8803:80 centos-nginx:v1 /usr/local/sbin/nginx "-g daemon off"
    
    #注意名字重复时,容器则会被覆盖
    
  • 相关阅读:
    HDU 6043 KazaQ's Socks
    HDU 6033 Add More Zero
    D
    D
    L
    关于G
    excel函数实现下拉框控制显示不同内容
    牛客网暑期ACM多校训练营(第五场)J-plan (模拟)
    牛客网暑期ACM多校训练营(第五场)G-max (math)
    牛客网暑期ACM多校训练营(第五场)A-gap (二分答案)
  • 原文地址:https://www.cnblogs.com/Gmiaomiao/p/13221353.html
Copyright © 2020-2023  润新知