• 基于容器制作镜像


    一。镜像基础

    一。基于容器制作镜像

      1. 查看并关联运行的容器

    [gh@localhost ~]$ docker container ls
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    4da438fc9a8e        busybox             "sh"                2 days ago          Up 3 seconds                            aaaaa
    [gh@localhost ~]$ docker container attach aaaaa
    / # 

      2. 创建文件夹和文件

    / # mkdir /var/html
    / # vi /var/html/index.html
    / # cat /var/html/index.html
    ............
    httpd
    ...........
    / # 

      3. 查看httpd服务帮助

    / # which httpd
    /bin/httpd
    / # httpd -h
    -f        前台运行
    -h        家目录
    / # 

      4. 制作镜像

    ---- docker container commit --help

    -a:作者信息

    -c:修改COMMAND,即容器主程序

    -m:说明

    -p:暂停容器

    [gh@localhost ~]$ docker container commit -a "name <abc@163.com>" -c 'CMD ["/bin/httpd","-f","-h","/var/html"]' -p aaaaa myhttpd:v9.0
    sha256:9fdc2c89794f1d716a8ef3c90e4109991210e48fed46fa3f76dd9d35cc2e636f
    [gh@localhost ~]$ docker image ls |grep "myhttpd"
    myhttpd             v9.0                9fdc2c89794f        18 seconds ago      1.13MB
    [gh@localhost ~]$ 

      5. 运行镜像

    [gh@localhost ~]$ docker container run --name httpd -d myhttpd:v9.0 
    e51a67a0346bd766b0716d6e0b2f5c101d98d45a0afd04a5b7f6ebc8007c24e1
    [gh@localhost ~]$ docker container ls
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
    e51a67a0346b        myhttpd:v9.0        "/bin/httpd -f -h /v…"   6 seconds ago       Up 5 seconds                            httpd
    4da438fc9a8e        busybox             "sh"                     2 days ago          Up 6 minutes                            aaaaa
    [gh@localhost ~]$ 

      6. 访问服务

    [gh@localhost ~]$ curl 172.17.0.3
    ............
    httpd
    ...........
    [gh@localhost ~]$ 

      7. 与容器关联

    [gh@localhost ~]$ docker container exec -it httpd /bin/sh
    / # ps -e
    PID   USER     TIME   COMMAND
        1 root       0:00 /bin/httpd -f -h /var/html
       11 root       0:00 /bin/sh
       16 root       0:00 ps -e
    / # 

       8. 登陆阿里云仓库(密码保存在家目录 .docker/config.json)

    [gh@localhost ~]$ docker login --username=name registry.cn-shenzhen.aliyuncs.com
    Password: 
    Login Succeeded
    [gh@localhost ~]$

      9. 修改标签(阿里云仓库里有操作说明)

    [gh@localhost ~]$ docker image ls |grep "myhttpd"
    myhttpd             v9.0                9fdc2c89794f        13 hours ago        1.13MB
    [gh@localhost ~]$ docker image tag 9fdc2c89794f registry.cn-shenzhen.aliyuncs.com/ghh/test:v9.9
    [gh@localhost ~]$ docker image ls |grep "9fdc2c89794f"
    myhttpd                                      v9.0                9fdc2c89794f        13 hours ago        1.13MB
    registry.cn-shenzhen.aliyuncs.com/ghh/test   v9.9                9fdc2c89794f        13 hours ago        1.13MB
    [gh@localhost ~]$ 

      10. 推送镜像

    [gh@localhost ~]$ docker image push registry.cn-shenzhen.aliyuncs.com/ghh/test:v9.9
    The push refers to repository [registry.cn-shenzhen.aliyuncs.com/ghh/test]
    49946ae5d4d2: Pushed 
    6a749002dd6a: Pushed 
    v9.9: digest: sha256:096ff2618334d8c79750770c1ac20ba6d8f33c6945dafaa7ae17bbbe3eafe5a2 size: 734
    [gh@localhost ~]$ 

      11. 登出

  • 相关阅读:
    【DL】如何使用MMSegmentation训练数据集
    【python基础】Python错误:AttributeError: module 'json' has no attribute 'loads'解决办法
    【python基础】如何理解Python装饰器?
    【DL】如何生成用于训练的数据集
    【pytorch基础】基于训练的pytorch模型转换为onnx模型并测试
    【python基础】JupyterNotebook配置远程登录
    【工具使用】标注工具Labelme的安装以及使用
    【leetcode_easy_math】892. Surface Area of 3D Shapes
    【leetcode_easy】1636. Sort Array by Increasing Frequency
    【leetcode_easy】1640. Check Array Formation Through Concatenation
  • 原文地址:https://www.cnblogs.com/GH-123/p/10226604.html
Copyright © 2020-2023  润新知