(作者:陈玓玏)

1、给我一个必须修改镜像的理由

安装好docker后,意欲试用一下docker,于是输入sudo docker run hello-world,结果提示:

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 127.0.1.1:53: read udp 127.0.0.1:54341->127.0.1.1:53: i/o timeout.
See 'docker run --help'

也就是说,找不到镜像,于是尝试找一下镜像:

sudo docker search hello-world

提示:

Warning: failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/info: dial unix /var/run/docker.sock: connect: permission denied). Using system default: https://index.docker.io/v1/
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/search?limit=25&term=hello-world: dial unix /var/run/docker.sock: connect: permission denied

于是尝试找一个绝对不可能找不到的镜像;

sudo docker search ubuntu

结果提示:

Error response from daemon: Get https://index.docker.io/v1/search?q=ubuntu&n=25: dial tcp: lookup index.docker.io on 127.0.1.1:53: read udp 127.0.0.1:60246->127.0.1.1:53: i/o timeout

这下小伙伴说,必须修改镜像源才行了,现在的镜像用不了,连接以后速度太慢,总是会出现timeout错误。

2、怎么修改镜像源

我当前是root用户,所以不用加sudo。
1)打开配置文件

gedit /etc/docker/daemon.json

2)修改配置文件
这里用的是网易的镜像,你也可以用阿里的、豆瓣的,还有一些学校的,像中科大、清华什么的,只要把那个网址改掉就好了。改完之后把文件保存好。

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

3)检查修改效果
输入

docker search ubuntu

结果如下,说明成功了;

NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                 Ubuntu is a Debian-based Linux operating sys…   8242                [OK]                
dorowu/ubuntu-desktop-lxde-vnc                         Ubuntu with openssh-server and NoVNC            212                                     [OK]
rastasheep/ubuntu-sshd                                 Dockerized SSH service, built on top of offi…   167                                     [OK]
consol/ubuntu-xfce-vnc                                 Ubuntu container with "headless" VNC session…   126                                     [OK]
ansible/ubuntu14.04-ansible                            Ubuntu 14.04 LTS with ansible                   95                                      [OK]
ubuntu-upstart                                         Upstart is an event-based replacement for th…   87                  [OK]                
neurodebian                                            NeuroDebian provides neuroscience research s…   52                  [OK]                
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          43                                      [OK]
ubuntu-debootstrap                                     debootstrap --variant=minbase --components=m…   39                  [OK]                
nuagebec/ubuntu                                        Simple always updated Ubuntu docker images w…   23                                      [OK]
tutum/ubuntu                                           Simple Ubuntu docker images with SSH access     18                                      
i386/ubuntu                                            Ubuntu is a Debian-based Linux operating sys…   13                                      
ppc64le/ubuntu                                         Ubuntu is a Debian-based Linux operating sys…   12                                      
1and1internet/ubuntu-16-apache-php-7.0                 ubuntu-16-apache-php-7.0                        12                                      [OK]
eclipse/ubuntu_jdk8                                    Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, …   6                                       [OK]
codenvy/ubuntu_jdk8                                    Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, …   4                                       [OK]
darksheer/ubuntu                                       Base Ubuntu Image -- Updated hourly             4                                       [OK]
1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4      ubuntu-16-nginx-php-5.6-wordpress-4             3                                       [OK]
1and1internet/ubuntu-16-sshd                           ubuntu-16-sshd                                  1                                       [OK]
pivotaldata/ubuntu                                     A quick freshening-up of the base Ubuntu doc…   1                                       
ossobv/ubuntu                                          Custom ubuntu image from scratch (based on o…   0                                       
1and1internet/ubuntu-16-healthcheck                    ubuntu-16-healthcheck                           0                                       [OK]
1and1internet/ubuntu-16-rspec                          ubuntu-16-rspec                                 0                                       [OK]
smartentry/ubuntu                                      ubuntu with smartentry                          0                                       [OK]
pivotaldata/ubuntu-gpdb-dev                            Ubuntu images for GPDB development              0   
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐