docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]docker pull --help可以看到使用方法:noamanelson@noamanelson-Virtual-Machine:~$ docker pull --help
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Download an image from a registry
Aliases:
docker image pull, docker pull
Options:
-a, --all-tags Download all tagged images in the repository
--disable-content-trust Skip image verification (default true)
--platform string Set platform if server is multi-platform capable
-q, --quiet Suppress verbose output
noamanelson@noamanelson-Virtual-Machine:~$/ | 说明 |
|---|---|
镜像仓库 | 格式: |
仓库名 | 格式: |
docker pull ubuntu:18.04如上没有给出 Docker 镜像仓库地址,因此将会从 Docker Hub 获取镜像; 镜像名称是ubuntu:18.04 ,将会获取官方镜像 library/ubuntu 仓库中标签为 18.04 的镜像。
noamanelson@noamanelson-Virtual-Machine:~$ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
0c5227665c11: Pull complete
Digest: sha256:8aa9c2798215f99544d1ce7439ea9c3a6dfd82de607da1cec3a8a2fae005931b
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
noamanelson@noamanelson-Virtual-Machine:~$ bash 并且进行交互式操作:docker run -it --rm ubuntu:18.04 bashnoamanelson@noamanelson-Virtual-Machine:~$ docker run -it --rm ubuntu:18.04 bash
root@36e7bfa463f2:/#
root@36e7bfa463f2:/#
root@36e7bfa463f2:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@36e7bfa463f2:/# docker run --help查看:noamanelson@noamanelson-Virtual-Machine:~$ docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Create and run a new container from an image
Aliases:
docker container run, docker run
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cgroupns string Cgroup namespace to use (host|private)
......docker run就是运行容器;参数 | 说明 |
|---|---|
|
|
| 容器退出后将其删除 |
| 指定镜像做为基础启动容器 |
| 放在镜像名后的是 命令,交互式 |
shell中输入任何命令,比如查看系统版本:noamanelson@noamanelson-Virtual-Machine:~$ docker run -it --rm ubuntu:18.04 bash
root@63f52d50f22d:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bioniexit退出容器。docker image ls:noamanelson@noamanelson-Virtual-Machine:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 3941d3b032a8 2 months ago 63.1MB
hello-world latest feb5d9fea6a5 19 months ago 13.3kB
noamanelson@noamanelson-Virtual-Machine:~$ 参数 | 说明 |
|---|---|
| 仓库名 |
| 标签 |
| 镜像ID |
| 创建时间 |
| 占用空间 |
Docker Hub 上看到的镜像大小不同;Docker Hub 是压缩后的体积;docker system df查看镜像、容器、数据卷所占用的空间:noamanelson@noamanelson-Virtual-Machine:~$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 2 1 63.16MB 63.15MB (99%)
Containers 1 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
noamanelson@noamanelson-Virtual-Machine:~$ <none>;
-虚悬镜像已经失去了存在的价值,是可以随意删除,删除命令为:docker image prunedocker image ls列表中只会显示顶层镜像;docker image ls -a显示包括中间层镜像在内的所有镜像;docker image ls其实就比如linux下的ls后跟一些参数,比如docker image ls ubuntu;docker image ls 还支持强大的过滤器参数 --filter ,或者简写 -f;docker image ls -f since=xxx或者把since换成before。docker image rm; docker image rm [选项] <镜像1> [<镜像2> ...]noamanelson@noamanelson-Virtual-Machine:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 3941d3b032a8 2 months ago 63.1MB
hello-world latest feb5d9fea6a5 19 months ago 13.3kB
noamanelson@noamanelson-Virtual-Machine:~$ docker image rm 394
Untagged: ubuntu:18.04
Untagged: ubuntu@sha256:8aa9c2798215f99544d1ce7439ea9c3a6dfd82de607da1cec3a8a2fae005931b
Deleted: sha256:3941d3b032a8168d53508410a67baad120a563df67a7959565a30a1cb2114731
Deleted: sha256:b7e0fa7bfe7f9796f1268cca2e65a8bfb1e010277652cee9a9c9d077a83db3c4
noamanelson@noamanelson-Virtual-Machine:~$ Untagged 和 Deleted;Untagged其实就是镜像的所有标签,因为一个镜像可以有多个标签;Delete 行为就不会发生;docker image rm 都会产生删除镜像的行为,有可能仅仅是取消了某个标签
而已;
当该镜像所有的标签都被取消了,该镜像很可能会失去了存在的意义,因此会触发删除行为。ubuntu 的镜像: docker image rm $(docker image ls -q ubuntu)noamanelson@noamanelson-Virtual-Machine:~$ docker image rm $(docker image ls -q ubuntu)
Untagged: ubuntu:18.04
Untagged: ubuntu@sha256:8aa9c2798215f99544d1ce7439ea9c3a6dfd82de607da1cec3a8a2fae005931b
Deleted: sha256:3941d3b032a8168d53508410a67baad120a563df67a7959565a30a1cb2114731
Deleted: sha256:b7e0fa7bfe7f9796f1268cca2e65a8bfb1e010277652cee9a9c9d077a83db3c4
noamanelson@noamanelson-Virtual-Machine:~$ 原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。