docker官方的镜像库比较慢,在进行镜像操作之前,需要将镜像源设置为国内的站点。
新建文件/etc/docker/daemon.json,输入如下内容:
{ "registry-mirrors" : [ "https://registry.docker-cn.com", "https://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com", "https://cr.console.aliyun.com/" ] }
然后重启docker的服务:
systemctl restart docker
3.1 列出本地所有镜像
执行命令 docker images 可以查看
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 20.04 f643c72bc252 5 weeks ago 72.9MB hello-world latest bf756fb1ae65 12 months ago 13.3kB
当前我本地只有刚才安装的两个镜像。
3.2 从镜像库中查找镜像
执行命令 docker search 镜像名称可以从docker镜像库中查找镜像。
$ docker search python NAME DESCRIPTION STARS OFFICIAL AUTOMATED python Python is an interpreted, interactive, objec… 5757 [OK] django Django is a free web application framework, … 1039 [OK] pypy PyPy is a fast, compliant alternative implem… 260 [OK] joyzoursky/python-chromedriver Python with Chromedriver, for running automa… 57 [OK] nikolaik/python-nodejs Python with Node.js 57 [OK] arm32v7/python Python is an interpreted, interactive, objec… 53 circleci/python Python is an interpreted, interactive, objec… 42 centos/python-35-centos7 Platform for building and running Python 3.5… 38 centos/python-36-centos7 Platform for building and running Python 3.6… 30 hylang Hy is a Lisp dialect that translates express… 29 [OK] arm64v8/python Python is an interpreted, interactive, objec… 24 revolutionsystems/python Optimized Python Images 18 centos/python-27-centos7 Platform for building and running Python 2.7… 17 bitnami/python Bitnami Python Docker Image 10 [OK] publicisworldwide/python-conda Basic Python environments with Conda. 6 [OK] d3fk/python_in_bottle Simple python:alpine completed by Bottle+Req… 5 [OK] dockershelf/python Repository for docker images of Python. Test… 5 [OK] clearlinux/python Python programming interpreted language with… 4 i386/python Python is an interpreted, interactive, objec… 3 ppc64le/python Python is an interpreted, interactive, objec… 2 centos/python-34-centos7 Platform for building and running Python 3.4… 2 amd64/python Python is an interpreted, interactive, objec… 1 ccitest/python CircleCI test images for Python 0 [OK] s390x/python Python is an interpreted, interactive, objec… 0 saagie/python Repo for python jobs 0
最好选择官方(OFFICIAL)的镜像,这样的镜像最稳定一些。
3.3 下载新的镜像
执行命令docker pull 镜像名称:版本号即可下载新的镜像。
$ docker pull python:3.8 3.8: Pulling from library/python 6c33745f49b4: Pull complete ef072fc32a84: Pull complete c0afb8e68e0b: Pull complete d599c07d28e6: Pull complete f2ecc74db11a: Pull complete 26856d31ce86: Pull complete 2cd68d824f12: Pull complete 7ea1535f18c3: Pull complete 2bef93d9a76e: Pull complete Digest: sha256:9079aa8582543494225d2b3a28fce526d9a6b06eb06ce2bac3eeee592fcfc49e Status: Downloaded newer image for python:3.8 docker.io/library/python:3.8
镜像下载后,就可以使用镜像来创建容器了。