1、国内环境拉取docker镜像之前最好检查是否可用(这里以centos为例)

docker search centos

如果报网络错误,则一般是GFW的原因

2、配置docker镜像加速器

vi /etc/docker/daemon.json

{"registry-mirrors": ["docker.mirrors.ustc.edu.cn"], "insecure-registries":[]}
重新启动docker;

(在这里,我始终觉得配置加速器不是最好的方法,因为网络时好时坏,比如quay.io/coreos/flannel的镜像就经常不可获取,找到最好的方法会回来修改,如果谁有更好的欢迎留言)

3、获取镜像(默认获取centos:latest,如果要根据版本获取即centos:7.4.1708)

docker pull centos:7.4.1708

4、查看docker获取的所有镜像

docker images

或者只查看centos镜像

docker images centos

5、在docker中运行镜像

docker run -it docker.io/centos:7.4.1708   #已镜像名运行

docker run -it docker.io/centos:7.4.1708  /bin/bash

docker run -it 3afd47092a0e   #以镜像ID运行镜像

(可以看到进入了centos bash环境,exit退出即可)

[root@8d25fc664da9 /]# exit
exit

6、删除docker镜像

docker rmi docker.io/centos:7.4.1708 
或者docker rmi 3afd47092a0e   #如果多个镜像ID相同,则使用镜像名删除

如果因为镜像被引用而无法删除镜像,则强制删除

docker rmi -f docker.io/centos:7.4.1708


#错误总结

1、docker pull报错

[1]dial tcp: lookup index.docker.io: no such host

很有可能是无法访问外网、或者/etc/docker/daemon.json加速器配置错误

2、docker rmi报错

[1]Error response from daemon: conflict: unable to remove repository reference "quay.io/coreos/flannel:v0.9.1-amd64" (must force) - container fbee5cbe37e6 is using its referenced image 1c58604b7710

[2]Error response from daemon: conflict: unable to delete 1c58604b7710 (must be forced) - image is being used by stopped container 08cf943562b1

以上错误都需要docker rmi -f强制删除即可


Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐