一、简介
Docker镜像是指一个Docker的可执行文件,包括运行程序所需的所有代码内容、依赖库、环境变量和配置文件等。它可以创建一个或者多个容器
二、镜像操作
1、镜像查看
命令格式:docker images [options] [repository[:tag]]
'''
options是参数
-a,--all 显示所有镜像
-q, --quiet 只显示镜像ID
--no-trunc 不缩略显示
repository是镜像名
tag是标签
'''
# 例子
[root@192 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python 3.6 6b0219e0ed75 4 weeks ago 874MB
[root@192 docker]# docker images -q python
6b0219e0ed75
'''
TAG:镜像标签
IMAGE ID:镜像ID
CREATED:镜像的创建日期(不是获取该镜像的日期)
SIZE:镜像大小
'''
2、搜索镜像
# 命令格式: docker search [option] TERM
'''
命令参数
-f,--filter filter 对搜索指定条件的结果
--format string 利用Go语言的forms格式化输出结果
--limit int 展示最大结果数字,默认是25
--no-trunc 内容全部显示
'''
# 案例
[root@192 docker]# docker search --limit 4 python:3.6
NAME DESCRIPTION STARS OFFICI
tnir/mysqlclient the Python's mysqlclient Docker image (based… 1
mc706/pipenv-3.6 python:3.6 + pipenv 0
csig/qci-python3 official python:3.6-stretch with qci-agent 0
eamonwoortman/alpine-python-curl-zip A python:3.6-alpine image which has curl and… 0
[root@192 docker]#
[root@192 docker]# docker search --limit 3 --no-trunc python
NAME DESCRIPTION OFFICIAL AUTOMATED
python Python is an interpreted, interactive, object-oriented, open-source programmin [OK]
nikolaik/python-nodejs Python with Node.js [OK]
circleci/python Python is an interpreted, interactive, object-oriented, open-source programmin
'''
NAME:仓库名称
DESCRIPTION:镜像描述
STARS:用户评价,反应一个镜像的受欢迎程度
OFFICIAL:是否官方
AUTOMATED:自动构建,表示该镜像由Docker Hub自动构建流程创建的
'''
也可以在Docker Hub上搜索镜像,它跟github类似
3、镜像下载
# 命令格式:docker pull [OPTIONS] NAME[:TAG|@DIGEST]
# 命令参数[options]:
# -a, --all-tags 下载所有符合给定tag镜像
# 例子
[root@192 docker]# docker pull python:3.6
3.6: Pulling from library/python
b9a857cbf04d: Pull complete
d557ee20540b: Pull complete
3b9ca4f00c2e: Pull complete
...
Digest: sha256:da022140db3b40d07c81815158092ff8ccfd967926b533a7c0b573eeeb5be120
Status: Downloaded newer image for python:3.6
docker.io/library/python:3.6
4、镜像删除
#命令: docker rmi 镜像名字/ID号
# docker rmi -f/--force 镜像名字/ID号 强制删除
# 例子:
[root@192 docker]# docker rmi 621
Untagged: redis:latest
Untagged: redis@sha256:0f97c1c9daf5b69b93390ccbe8d3e2971617ec4801fd0882c72bf7cad3a13494
Deleted: sha256:621ceef7494adfcbe0e523593639f6625795cc0dc91a750629367a8c7b3ccebb
Deleted: sha256:de66cfbf4712b8ba9ef292e08ef7487be26d9d21b350548e400ae351405d820e
5、镜像的其他操作
# ------------镜像保存备份---------------
'''
# 作用:将本地的一个或多个镜像打包保存成本地tar文件(输出到STDOUT)
# 命令格式:
docker save [OPTIONS] IMAGE [IMAGE...]
# 命令参数(OPTIONS):
-o, --output string 指定写入的文件名和路径
# 例子:
docker save -o linux_images.tar centos ubuntu
'''
# ------------镜像备份导入---------------
'''
# 作用:将save命令打包的镜像导入本地镜像库中
# 命令格式:
docker load [OPTIONS]
# 命令参数(OPTIONS):
-i, --input string 指定要打入的文件,如没有指定,默认是STDIN
-q, --quiet 不打印导入过程信息
# 例子
docker load -i linux_images.tar
docker load -i linux_images.tar -q
'''
# ------------镜像重命名---------------
'''
# 作用:对本地镜像的NAME、TAG进行重命名,并新产生一个命名后镜像
# 命令格式:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
# 命令参数(OPTIONS):
无
# 例子
docker tag e934 centos-newname:newtag
'''
# ------------镜像详细信息---------------
'''
# 作用:查看本地一个或多个镜像的详细信息
# 命令格式:
docker image inspect [OPTIONS] IMAGE [IMAGE...]
或者 docker inspect [OPTIONS] IMAGE [IMAGE...]
# 命令参数(OPTIONS):
-f, --format string 利用特定Go语言的format格式输出结果
# 例子:
docker image inspect -f "{{json .id}}" centos
docker image inspect -f "{{json .Created}}" centos
docker image inspect
'''
# ------------镜像历史信息---------------
'''
# 作用:查看本地一个镜像的历史(历史分层)信息
# 命令格式:
docker history [OPTIONS] IMAGE
# 命令参数(OPTIONS):
-H, --human 将创建时间、大小进行优化打印(默认为true)
-q, --quiet 只显示镜像ID
--no-trunc 不缩略显示
# 例子
docker history ubuntu
docker history ubuntu -H=false
'''
总结:
