docker 镜像常用部分命令
帮助命令
docker version # 显示docker的版本信息
docker info # 显示docker的系统信息,包括镜像和容器
docker 命令 --help # 帮助命令
帮助文档地址: https://docs.docker.com/engine/reference/commandline
镜像命令
可以在帮助文档里面找到 docker image 进行查看
docker images 查看镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 7 months ago 13.3kB # 解释 REPOSITORY 镜像的仓库 TAG 镜像的标签 IMAGE ID 镜像的id CREATED 镜像的创建时间 SIZE 镜像的大小 # 可选项 [root@localhost ~]# docker images --help Usage: docker images [OPTIONS] [REPOSITORY[:TAG]] Options: -a, --all #列出所有镜像 -q, --quiet #只显示镜像的ID
docker search 搜索镜像
[root@localhost ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 9848 [OK] mariadb MariaDB is a community-developed fork of MyS… 3598 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 720 [OK] # 可选项,通过搜索来过滤 [root@localhost ~]# docker search --help Usage: docker search [OPTIONS] TERM Options: -f, --filter filter Filter output based on conditions provided #只搜索数量大于3000的镜像 [root@localhost ~]# docker search mysql --filter=STARS=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 9848 [OK] mariadb MariaDB is a community-developed fork of MyS… 3598 [OK] [root@localhost ~]#
docker pull 下载镜像
[root@localhost ~]# docker pull --help Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] Options: -a, --all-tags Download all tagged images in the repository -q, --quiet Suppress verbose output # 下载镜像 docker pull 镜像名:tag [root@localhost ~]# docker pull mysql Using default tag: latest #如果不写tag,默认就是 latest latest: Pulling from library/mysql bf5952930446: Pull complete #分层下载,docker image的核心,联合文件系统 8254623a9871: Pull complete 938e3e06dac4: Pull complete ea28ebf28884: Pull complete f3cef38785c2: Pull complete 894f9792565a: Pull complete 1d8a57523420: Pull complete 6c676912929f: Pull complete ff39fdb566b4: Pull complete fff872988aba: Pull complete 4d34e365ae68: Pull complete 7886ee20621e: Pull complete Digest: sha256:c358e72e100ab493a0304bda35e6f239db2ec8c9bb836d8a427ac34307d074ed #签名 Status: Downloaded newer image for mysql:latest docker.io/library/mysql:latest #真实地址 docker pull mysql 等价于 docker pull docker.io/library/mysql:latest #指定版本下载 [root@localhost ~]# docker pull mysql:5.7 5.7: Pulling from library/mysql bf5952930446: Already exists #层级,因为下载最新版时已经有了,不重复下载,节省资源 8254623a9871: Already exists 938e3e06dac4: Already exists ea28ebf28884: Already exists f3cef38785c2: Already exists 894f9792565a: Already exists 1d8a57523420: Already exists 5f09bf1d31c1: Pull complete 1b6ff254abe7: Pull complete 74310a0bf42d: Pull complete d398726627fd: Pull complete Digest: sha256:da58f943b94721d46e87d5de208dc07302a8b13e638cd1d24285d222376d6d84 Status: Downloaded newer image for mysql:5.7 docker.io/library/mysql:5.7 [root@localhost ~]#
docker rmi 删除镜像
[root@localhost /]# docker rmi -f 镜像ID #删除指定镜像 [root@localhost /]# docker rmi -f 镜像ID1 镜像ID2 #删除多个镜像 [root@localhost /]# docker rmi -f $(docker images -qa) #删除全部镜像
docker save 提交镜像成tar包
docker save ubuntu:load>/root/ubuntu.tar
docker load<ubuntu.tar