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

mac2024-01-24  34

前言

      本章讲解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 quit Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders from a container's filesystem to the host path create Create a new container diff Inspect changes on a container's filesystem events Get real time events from the server exec Run a command in a running container export Stream the contents of a container as a tar archive history Show the history of an image images List images import Create a new filesystem image from the contents of a tarball info Display system-wide information inspect Return low-level information on a container or image kill Kill a running container load Load an image from a tar archive login Register or log in to a Docker registry server logout Log out from a Docker registry server logs Fetch the logs of a container pause Pause all processes within a container port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT ps List containers pull Pull an image or a repository from a Docker registry server push Push an image or a repository to a Docker registry server rename Rename an existing container restart Restart a running container rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save an image to a tar archive search Search for an image on the Docker Hub start Start a stopped container stats Display a stream of a containers' resource usage statistics stop Stop a running container tag Tag an image into a repository top Lookup the running processes of a container unpause Unpause a paused container version Show the Docker version information wait Block until a container stops, then print its exit code Run 'docker COMMAND --help' for more information on a command.

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

2.docker的镜像命令

1)docker images命令

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

docker images表格的属性说明:

REPOSITORY:镜像的仓库源TAG:镜像的标签(版本),可以使用REPOSITORY:TAG指定具体版本的镜像,如不指定,默认最新版本即latestIMAGE ID:镜像的IDCREATED:镜像的创建时间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:表示强制删除该镜像

最新回复(0)