1) 内网docker服务器:192.168.123.1,操作系统为:redhat 7.9
2) 代理服务器(可通外网):192.168.110.2,操作系统为:redhat 7.9
代理在这里我们使用的nginx,主要用于正向代理,将外部网址代理到内网,正向代理的原理和模块这里就不具体讲了,其配置为:
http模块中:
server {
resolver 61.139.2.69;
listen 9099;
resolver_timeout 30s;
proxy_connect;
proxy_connect_allow 443 80;
proxy_connect_connect_timeout 20s;
proxy_connect_read_timeout 20s;
proxy_connect_send_timeout 20s;
location / {
proxy_pass $scheme://$http_host$request_uri;
}
}
echo 'export http_proxy=http://192.168.110.2:9099
export https_proxy=http://192.168.110.2:9099' >> /etc/profile && source /etc/profile
curl http://nginx.org
curl https://www.baidu.com
当出现正常的网页访问则证明生效
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
vi /etc/yum.repos.d/Centos-7.repo
输入冒号,然后输入
%s/releaserver/7/g
替换整个文件中的关键字
yum clean all && yum clean all
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
更新源:
yum makecache fast
安装默认版本软件,官方默认使用最新的版本:
yum -y install docker-ce
查询并安装指定版本:
yum list docker-ce.x86_64 --showduplicates | sort -r
yum -y install docker-ce-[VERSION]
systemctl start docker
systemctl enable docker
docker version
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io on [::1]:53 read udp [::1]:45388->[::1]:53: read: connection refused
此时我们需要修改docker的服务配置,加入代理配置,从而正确解析域名:
查看服务,找到服务配置文件:
systemctl status docker
修改服务配置文件:
vi /usr/lib/systemd/system/docker.service
在[Service]下加入:
Enviroment="HTTP_PROXY=http://172.16.220.5:9095/" "HTTPS_PROXY=http://172.16.220.5:9095/" "NO_PROXY=localhost,127.0.0.1,*.docker.io.*,*.docker.com"
systemctl daemon-reload
systemctl restart docker
docker pull ubuntu
通过默认的镜像站获取镜像可能会比较慢,因此,我们可以配置国内的镜像站,从而加速镜像的拉取
登陆阿里云,搜索“容器镜像服务”,进入后点击“管理控制台”,找到“镜像工具”->“镜像加速器”,复制镜像加速器连接,配置内网服务器镜像daemon.json文件
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://bgx0ltz2.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker