20190821更新,使用https://registry.docker-cn.com 镜像更全
背景介绍
我司测试服务器位于内网,对于需要网络下载的应用场景非常不友好,因此需要为其设置网络代理进行互联网访问。
首先可参考以下文章
环境介绍
客户端:
Windows10
Fiddler v5.0.20182.28034 for .NET 4.6.1
Chocolatey
ssh client
服务器:
Centos 7.4
操作步骤
1. yum添加docker镜像源
>> sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#如果想添加国内源,可以用以下命令添加阿里云镜像
>> sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2. 安装docker
>> sudo yum install docker-ce docker-ce-cli containerd.io
<b>需要注意,由于docker最新版本是19.xx,但docker centos源中并没有这个这个版本的镜像,因此这步安装可能会失败</b>
如果安装失败,可以到docker package list 处下载镜像进行离线安装
以18.09.0-3.el7
为例,下载以下两个rpm镜像放置到服务器本地
运行安装命令
>>sudo yum install ./docker-ce-18.09.0-3.el7.x86_64.rpm
>>sudo yum install ./docker-ce-cli-18.09.0-3.el7.x86_64.rpm
等待命令运行结束,docker安装完成
3. 为docker添加国内仓库源
运行命令
sudo vim /etc/docker/daemon.json
写入文件(注意是https,有些文章介绍使用http地址http://hub-mirror.c.163.com),我尝试过,会找不到docker镜像。
{
"registry-mirrors": ["https://hub-mirror.c.163.com"]
}
4. 测试
运行命令
docker run hello-world
输出如下
Hello from Docker! This message shows that your installation appears
to be working correctly.To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)- The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.- The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/For more examples and ideas, visit:
https://docs.docker.com/get-started/
大功告成!