docker基础2--镜像基本操作

docker基础2–镜像、容器等基本操作:
1.查询镜像基础方法[高级方法,见cocker基础1]

docker search centos


[root@centos77 ~]# docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   6370                [OK]
ansible/centos7-ansible            Ansible on Centos7                              132                                     [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   125                                     [OK]
jdeathe/centos-ssh                 OpenSSH / Supervisor / EPEL/IUS/SCL Repos - …   117                                     [OK]
centos/systemd                     systemd enabled base container.                 93                                      [OK]
centos/mysql-57-centos7            MySQL 5.7 SQL database server                   87
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              58                                      [OK]
tutum/centos                       Simple CentOS docker image with SSH access      46
centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   45
kinogmt/centos-ssh                 CentOS with SSH                                 29                                      [OK]
pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   13
guyton/centos6                     From official centos6 container with full up…   10                                      [OK]


这里面的“OFFICIAL”是代表 官方发布的版本。“STARS”星星–个人理解就是热门版本,我们下载就是参照这两个参数就是可以了

2.查询系统中下载了哪些镜像

docker images

3.删除镜像的办法

docker rmi 镜像id

4.导出镜像
示例:以“busybox”为例进行测试


[root@centos77 ~]# docker save -o busy1.tar busybox:latest
[root@centos77 ~]#

[root@centos77 ~]# ls
1.txt    busy1.tar    install.sh  psutil-5.2.2.tar.gz



或者这样导出也可以


[root@centos77 ~]# docker save > busy2.tar busybox:latest
[root@centos77 ~]# ls
1.txt  anaconda-ks.cfg  busy1.tar  busy2.tar  
[root@centos77 ~]#


5.导入镜像
5.1先删除使用镜像的容器


[root@centos77 ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                    PORTS                    NAMES
1811ea42d922        busybox:latest        "/bin/sh"                2 days ago          Exited (137) 2 days ago                            vibrant_vaughan
156f134c5468        nginx                 "nginx -g 'daemon 
[root@centos77 ~]# docker rm 1811
1811

5.2在删除镜像


[root@centos77 ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
busybox               latest              b97242f89c8a        8 days ago          1.23MB

删除镜像busybox的id“b97242f89c8a”可以简写
[root@centos77 ~]# docker rmi b97
Untagged: busybox:latest
Untagged: busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f
Deleted: sha256:b97242f89c8a29d13aea12843a08441a4bbfc33528f55b60366c1d8f6923d0d4
Deleted: sha256:0064d0478d0060343cb2888ff3e91e718f0bffe9994162e8a4b310adb2a5ff74
[root@centos77 ~]#

5.3导出镜像
进入镜像所在的目录,然后执行导入命令


[root@centos77 ~]# ls
1.txt  anaconda-ks.cfg  busy1.tar  busy2.tar  initial-setup-ks.cfg  install.sh  psutil-5.2.2.tar.gz
[root@centos77 ~]# docker load -i busy1.tar
0064d0478d00: Loading layer [==================================================>]   1.45MB/1.45MB
Loaded image: busybox:latest
[root@centos77 ~]#


在查询下就是可以看到镜像已经导入进去了
[root@centos77 ~]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
busybox               latest              b97242f89c8a        8 days ago          1.23MB

猜你喜欢

转载自blog.csdn.net/wtt234/article/details/112980322