一:拉取镜像
1、国内连接docker官网很慢修改docker中配置,添加对应中国docker加速器。
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"live-restore": true
}
2、运行以下命令(本处以hello-world为例),将image文件从仓库拉去到本地。
docker pull library/hello-world
其中拉去命令为docker pull。hello-world为image为名称,library为hello-world镜像所在组。
执行完成后执行docker images可以查询。
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 4ab4c602aa5e 2 months ago 1.84kB
ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
3、运行拉去成功的image,docker run XXX
docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
hello-world运行完成后会自动关闭,类似myssql这样的服务类image运行后不会自动关闭。可以执行docker stop imageName停止。
二、查看iamge位置
1、docker镜像保存在/var/lib/docker/ 目录下
/var/lib/docker# ls
builder buildkit containerd containers image network overlay2 plugins runtimes swarm tmp trust volumes
2、进入containerd目录可以查看相应iamge
/var/lib/docker/containers# ls
4dabf98c9d09234babaa8587e61c6e36e46788e68085df25813d91fdfcc0f990 c4707b15e72381c0f1a71959266397437bd91421d1a62c48213d1d012a875d89
a9dd7aeba4b2477bf0fcdaf7657ca66209d5d220caad1f331e1b053e5d3922ca cfe45e1fb45ee40987b884e15db84c18e969e98a44c23332c0a40c9bd49cb6b1
bb2966bb77484e46dc91eef0983ccf7e747661e2f5f6248e11a60cbfa81a380c e9486c384b6d00e65d6f43c856751ee47cc8af88b0b5238be1971b3ae6dfcbb1
3、.在containers同级目录,有个叫image的文件夹,进入后
cd images/aufs
distribution imagedb layerdb repositories.json
在 repositories.json文件中记录了iamge的信息。
{"Repositories":{"hello-world":{"hello-world:latest":"sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f","hello-world@sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788":"sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f"},"ubuntu":{"ubuntu:15.10":"sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698","ubuntu@sha256:02521a2d079595241c6793b2044f02eecf294034f31d6e235ac4b2b54ffc41f3":"sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698"}}}
有些iamge文件夹下没有aufs目录,可能是这样的
/var/lib/docker/image# ls
overlay2
同样进入到overlay2文件夹下,可以看到aufs中相同的内容
/var/lib/docker/image/overlay2# ls
distribution imagedb layerdb repositories.json