• 容器rootfs命令


    容器rootfs命令

    commit

    **docker commit 😗*从容器创建一个新的镜像。

    语法

    docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
    
    • 1

    OPTIONS说明:

    • **-a 😗*提交的镜像作者;

    • **-c 😗*使用Dockerfile指令来创建镜像;

    • **-m 😗*提交时的说明文字;

    • **-p 😗*在commit时,将容器暂停。

    实例 – 在Ubuntu中安装vim

    docker exec -it abce9bcaf87c /bin/bash
    apt-get update
    apt-get install -y vim
    
    • 1
    • 2
    • 3

    此时可以使用vim命令

    此时我们可以理解分层的好处了,就是共享资源,方便复制迁移,就是为了复用

    多个镜像都从相同的镜像base镜像架构而来,那么docker host只需要在磁盘上保存一份base镜像,而且内存中每一层镜像都可以被共享。

    docker commit -m="vim cmd add ok" -a="nsddd" 08d1e4ac02f2  smile/myubuntu:版本号
    
    • 1

    image-20220510211036779

    docker中镜像分层,支持通过扩展现有镜像,创建新的镜像,类似于java继承与一个base基础类,自己再按需扩展,新的镜像就是从base镜像一层层的叠加生成的,每安装一个软件,就在现有的镜像的基础上增加一层镜像。

    将容器a404c6c174a2 保存为新的镜像,并添加提交人信息和说明信息。

    runoob@runoob:~$ docker commit -a "runoob.com" -m "my apache" a404c6c174a2  mymysql:v1 
    sha256:37af1236adef1544e8886be23010b66577647a40bc02c0885a6600b33ee28057
    runoob@runoob:~$ docker images mymysql:v1
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    mymysql             v1                  37af1236adef        15 seconds ago      329 MB
    
    • 1
    • 2
    • 3
    • 4
    • 5

    命名空间

    因为如果我们使用hub.docker 的话可能访问太慢了。所以选择hub可能不是很明治的选择,所以使用aliyun是一个很好的选择。

    image-20220510210523765

    添加个人仓库

    image-20220510210831886

    注意欸,要在下面的访问凭证设置密码

    完整的阿里云推送和拉取过程

    root@ubuntu:/# docker ps
    CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS      NAMES
    08d1e4ac02f2   ubuntu    "bash"                   18 minutes ago   Up 18 minutes              cranky_babbage
    a22dd4f7caf4   redis     "docker-entrypoint.s…"   24 hours ago     Up 24 hours     6379/tcp   strange_elgamal
    root@ubuntu:/# ls
    bin   c      chain  docker  home              lib    lib64   lost+found  mnt    opt   proc  run   snap  swapfile  tmp  var
    boot  cdrom  dev    etc     hyerledgerFabric  lib32  libx32  media       nginx  pbft  root  sbin  srv   sys       usr  vpn
    root@ubuntu:/# docker commit -m="vim cmd add ok" -a="nsddd" 08d1e4ac02f2  smile/myubuntu
    sha256:6962da3091d10456d52b8771f35d94dc01520e1ec661103438c77d6bb87d5d6f
    root@ubuntu:/# docker images
    REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
    smile/myubuntu   latest    6962da3091d1   20 seconds ago   108MB
    smile/ubuntu     3.7       4b9109b3e917   23 hours ago     0B
    <none>           <none>    c717164f2c33   23 hours ago     0B
    smile/ubuntu     1         ebc64f915192   23 hours ago     0B
    tomcat           latest    fb5657adc892   4 months ago     680MB
    redis            latest    7614ae9453d1   4 months ago     113MB
    python           latest    a5d7930b60cc   4 months ago     917MB
    ubuntu           latest    ba6acccedd29   6 months ago     72.8MB
    root@ubuntu:/# docker login --username=3293172751nss registry.cn-hangzhou.aliyuncs.com
    Password: 
    WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    Configure a credential helper to remove this warning. See
    https://docs.docker.com/engine/reference/commandline/login/#credentials-store
    
    Login Succeeded
    root@ubuntu:/# docker tag 6962da3091d1 registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu
    root@ubuntu:/# docker push registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu
    Using default tag: latest
    The push refers to repository [registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu]
    57fc73d61f9a: Pushed 
    9f54eef41275: Pushed latest: digest: sha256:08bb12c0c5d3a3449c3b1e06381a2eb9e3e43bc252237b4ba5e79f917adbcd6b size: 741
    root@ubuntu:/# docker rmi -f 6962da3091d1
    Untagged: smile/myubuntu:latest
    Untagged: registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu:latest
    Untagged: registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu@sha256:08bb12c0c5d3a3449c3b1e06381a2eb9e3e43bc252237b4ba5e79f917adbcd6b
    Deleted: sha256:6962da3091d10456d52b8771f35d94dc01520e1ec661103438c77d6bb87d5d6f
    Deleted: sha256:d442f4d51ca04c56cec20bc9dfda5e7ceb7e227145fe7cbfe89fafd36e022fc0
    root@ubuntu:/# docker images
    REPOSITORY     TAG       IMAGE ID       CREATED        SIZE
    smile/ubuntu   3.7       4b9109b3e917   24 hours ago   0B
    <none>         <none>    c717164f2c33   24 hours ago   0B
    smile/ubuntu   1         ebc64f915192   24 hours ago   0B
    tomcat         latest    fb5657adc892   4 months ago   680MB
    redis          latest    7614ae9453d1   4 months ago   113MB
    python         latest    a5d7930b60cc   4 months ago   917MB
    ubuntu         latest    ba6acccedd29   6 months ago   72.8MB
    root@ubuntu:/# docker rmi -f ba6acccedd29   4b9109b3e917 c717164f2c33  717164f2c33 
    Untagged: smile/ubuntu:3.7
    Deleted: sha256:4b9109b3e9172fbbfc797578772925f78bcb0007cf9c5204ee9e3820075284c2
    Deleted: sha256:c717164f2c33d6edea7055110293bb2f65c1bb5ba97b5a43b9c9202d312b5942
    Error response from daemon: conflict: unable to delete ba6acccedd29 (cannot be forced) - image is being used by running container 08d1e4ac02f2
    Error: No such image: 717164f2c33
    root@ubuntu:/# docker images
    REPOSITORY     TAG       IMAGE ID       CREATED        SIZE
    smile/ubuntu   1         ebc64f915192   24 hours ago   0B
    tomcat         latest    fb5657adc892   4 months ago   680MB
    redis          latest    7614ae9453d1   4 months ago   113MB
    python         latest    a5d7930b60cc   4 months ago   917MB
    ubuntu         latest    ba6acccedd29   6 months ago   72.8MB
    root@ubuntu:/# docker pull registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu
    Using default tag: latest
    latest: Pulling from nsddd/myubuntu
    7b1a6ab2e44d: Already exists 
    bc5f4eb531d0: Pull complete 
    Digest: sha256:08bb12c0c5d3a3449c3b1e06381a2eb9e3e43bc252237b4ba5e79f917adbcd6b
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu:latest
    registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu:latest
    root@ubuntu:/# docker images
    REPOSITORY                                         TAG       IMAGE ID       CREATED          SIZE
    registry.cn-hangzhou.aliyuncs.com/nsddd/myubuntu   latest    6962da3091d1   12 minutes ago   108MB
    smile/ubuntu                                       1         ebc64f915192   24 hours ago     0B
    tomcat                                             latest    fb5657adc892   4 months ago     680MB
    redis                                              latest    7614ae9453d1   4 months ago     113MB
    python                                             latest    a5d7930b60cc   4 months ago     917MB
    ubuntu                                             latest    ba6acccedd29   6 months ago     72.8MB
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
  • 相关阅读:
    Jetpack Compose 教程之 从一开始就投资于良好的导航框架将帮助您在之后节省大量的迁移工作
    黑马Java热门面试题SpringBoot(七)
    k8s-----14、controller-Job和Cronjob
    cocos2dx查看版本号的方法
    软考高级系统架构设计师系列案例考点专题二:系统开发基础考点梳理及精讲
    C++——string的封装
    UDP通信原理及网络编程
    c++征途 --- STL初识
    在iis上配置think php上传文件时报错“is not within the allowed path“
    软件测试面试(四)
  • 原文地址:https://blog.csdn.net/weixin_54707168/article/details/126716041