当前位置: 首页 > article >正文

Docker入门(二)Docker命令之镜像命令

前言

      本章讲解Docker常用命令之一的镜像命令

方法

1.永远的helloworld

我们知道,任何的语言和技术都有它入门的hello world。就如同我们刚开始学习java那样。

我们在什么也不清楚的时候运行我们的第一个命令:docker run hello-world观察效果如下:

这个画面代表着我们第一个docker学习的命令运行成功啦!Hello from Docker!

每当我们学习一个命令的时候,它的参数很复杂,我们可以使用命令+--help,docker也不例外。

使用命令docker --help观察docker的所有常用命令:

Options:--api-cors-header=                   Set CORS headers in the remote API-b, --bridge=                        Attach containers to a network bridge--bip=                               Specify network bridge IP-D, --debug=false                    Enable debug mode-d, --daemon=false                   Enable daemon mode--default-gateway=                   Container default gateway IPv4 address--default-gateway-v6=                Container default gateway IPv6 address--default-ulimit=[]                  Set default ulimits for containers--dns=[]                             DNS server to use--dns-search=[]                      DNS search domains to use-e, --exec-driver=native             Exec driver to use--exec-opt=[]                        Set exec driver options--exec-root=/var/run/docker          Root of the Docker execdriver--fixed-cidr=                        IPv4 subnet for fixed IPs--fixed-cidr-v6=                     IPv6 subnet for fixed IPs-G, --group=docker                   Group for the unix socket-g, --graph=/var/lib/docker          Root of the Docker runtime-H, --host=[]                        Daemon socket(s) to connect to-h, --help=false                     Print usage--icc=true                           Enable inter-container communication--insecure-registry=[]               Enable insecure registry communication--ip=0.0.0.0                         Default IP when binding container ports--ip-forward=true                    Enable net.ipv4.ip_forward--ip-masq=true                       Enable IP masquerading--iptables=true                      Enable addition of iptables rules--ipv6=false                         Enable IPv6 networking-l, --log-level=info                 Set the logging level--label=[]                           Set key=value labels to the daemon--log-driver=json-file               Default driver for container logs--log-opt=map[]                      Set log driver options--mtu=0                              Set the containers network MTU-p, --pidfile=/var/run/docker.pid    Path to use for daemon PID file--registry-mirror=[]                 Preferred Docker registry mirror-s, --storage-driver=                Storage driver to use--selinux-enabled=false              Enable selinux support--storage-opt=[]                     Set storage driver options--tls=false                          Use TLS; implied by --tlsverify--tlscacert=~/.docker/ca.pem         Trust certs signed only by this CA--tlscert=~/.docker/cert.pem         Path to TLS certificate file--tlskey=~/.docker/key.pem           Path to TLS key file--tlsverify=false                    Use TLS and verify the remote--userland-proxy=true                Use userland proxy for loopback traffic-v, --version=false                  Print version information and quitCommands:attach    Attach to a running containerbuild     Build an image from a Dockerfilecommit    Create a new image from a container's changescp        Copy files/folders from a container's filesystem to the host pathcreate    Create a new containerdiff      Inspect changes on a container's filesystemevents    Get real time events from the serverexec      Run a command in a running containerexport    Stream the contents of a container as a tar archivehistory   Show the history of an imageimages    List imagesimport    Create a new filesystem image from the contents of a tarballinfo      Display system-wide informationinspect   Return low-level information on a container or imagekill      Kill a running containerload      Load an image from a tar archivelogin     Register or log in to a Docker registry serverlogout    Log out from a Docker registry serverlogs      Fetch the logs of a containerpause     Pause all processes within a containerport      Lookup the public-facing port that is NAT-ed to PRIVATE_PORTps        List containerspull      Pull an image or a repository from a Docker registry serverpush      Push an image or a repository to a Docker registry serverrename    Rename an existing containerrestart   Restart a running containerrm        Remove one or more containersrmi       Remove one or more imagesrun       Run a command in a new containersave      Save an image to a tar archivesearch    Search for an image on the Docker Hubstart     Start a stopped containerstats     Display a stream of a containers' resource usage statisticsstop      Stop a running containertag       Tag an image into a repositorytop       Lookup the running processes of a containerunpause   Unpause a paused containerversion   Show the Docker version informationwait      Block until a container stops, then print its exit codeRun 'docker COMMAND --help' for more information on a command.

有点多哈,大家不要慌,本章仅仅是将基础的镜像命令哦!

2.docker的镜像命令

1)docker images命令

该命令用于列举出本地所拥有的镜像列表,使用docker images效果如下:

docker images表格的属性说明:

  • REPOSITORY:镜像的仓库源
  • TAG:镜像的标签(版本),可以使用REPOSITORY:TAG指定具体版本的镜像,如不指定,默认最新版本即latest
  • IMAGE ID:镜像的ID
  • CREATED:镜像的创建时间
  • VIRTUAL SIZE :镜像的大小

该命令该有一些其他的参数,这些参数可以组合使用:

  • -a:表示列举出本地所有的镜像(含中间映像层)
  • -q:表示只显示镜像的ID,可以在批量删除是组合使用
  • --digests:表示显示镜像的摘要信息,即备注
  • --no-trunc:表示显示镜像的完整ID

2)docker search XXX 命令

该命令用于查找远程仓库的镜像,需要指定镜像名称,如我们查找nginx的镜像,运行命令:docker search nginx

docker search 表格的属性说明:

  • NAME:镜像的名称
  • DESCRIPTION:镜像的描述
  • STARS:镜像的收藏数
  • OFFICIAL:是否为官方镜像
  • AUTOMATED:是否自动构建

我们在https://hub.docker.com/上搜索,同样可以得到如下的结果:

该命令该有一些其他的参数,这些参数可以组合使用:

  • --no-trunc:表示显示镜像的完整DESCRIPTION
  • -s:列举收藏数不小于指定值的镜像
  • --automated:列举出自动构建的镜像

3)docker pull XXX:[TAG] 命令

该命令用于拉取远程镜像仓库的镜像到本地仓库,需要附加镜像名称参数,如我们拉取nginx镜像:docker pull nginx

如果我们不加TAG的话,默认拉取最新的版本。

我们再次使用docker images列举镜像:

我们可以看到,我们的镜像被拉取到了本地仓库。

4)docker rmi XX 命令

该命令用于删除本地仓库的指定镜像,需要给出镜像ID

  • 删除一个镜像:docker rmi ID
  • 删除多个镜像:docker rmi ID1 ID2 ID3....
  • 删除全部镜像:docker rmi $(docker images -q)

该命令该有一些其他的参数:

  • -f:表示强制删除该镜像

http://www.lryc.cn/news/2419016.html

相关文章:

  • 很漂亮的个人主页(附带源码)
  • Compiling... ,Error spawning cl.exe 解决方法(转自http://hi.baidu.com/%D3%DE%C8%CB%B3%C2/blog/item/f5d43d3f
  • VMware虚拟机和主机之间共享文件夹以及文字和文件的复制功能开启
  • 366小游戏HTML5小游戏,使用Matter.js实现的H5雪球掉落小游戏
  • 【React实战技巧】——将数据库返回的时间转换为几分钟前、几小时前、几天前……
  • C语言指针高级部分:void指针和数据指针
  • Android一点 打造全功能屏幕适配AutoView
  • 深度解析JavaScript中常见设计模式及其应用场景,看完去面试,面试官说:就你了
  • 安卓期末大作业——安卓手机网上商城-2号店
  • JavaWeb实现简单的文件上传和下载
  • PerformanceCounter 性能计数器的使用
  • 六亿美金到数千万美元,西雅图行业先驱要私有化!
  • 问题解决:com.lowagie.text.DocumentException: Font 'STSong-Light' with 'UniGB-UCS2-H'
  • 软件开发完整流程整套文档(开发实施运维安全交付)
  • 超宽屏幕比例_显示器屏幕比例与分辨率对照表
  • C# 设计模式(一)
  • JCreator调试全攻略
  • 基于领域特定语言(DSL)的用例驱动开发(UDD)
  • 【YOLO使用】YOLOv5训练目标检测任务入门用法(一)
  • 文件系统格式FAT16、FAT32、NTFS、exFAT的区别
  • 什么是垂直搜索引擎
  • 【软件基础】面向对象分析与设计思想总结
  • freepascal linux 界面,FreePascal中的编译器选项
  • eclipse安装flash builder 4.7插件以及java、flex整合开发
  • MSF使用教程
  • h3c防火墙u200配置命令_绝了!华为、H3C、锐捷交换机配置命令大全
  • sort函数用法与stable_sort函数
  • 世界华人名人录
  • TypedArray的用法和declare-styleable:自定义控件的属性
  • 【IO】读写文件(FileInputStream、FileOutputStream、FileReader、FileWriter、RandomAccessFile)