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:表示强制删除该镜像