Docker设置代理

(1)国内很多镜像无法访问,因此需要配置代理访问外部镜像,配置方法如下:

json 复制代码
[root@dev ~]# vi /etc/docker/daemon.json 
{
  "iptables": false,
  "data-root": "/home/docker/store",
  "registry-mirrors": ["https://docker.m.daocloud.io",
    "https://huecker.io",
    "https://dockerhub.timeweb.cloud",
    "https://noohub.ru",
    "https://ipv4.mirrors.ustc.edu.cn",
    "https://tivt17e5.mirror.aliyuncs.com"],
  "proxies": {
    "http-proxy": "http://192.168.31.177:7890",
    "https-proxy": "http://192.168.31.177:7890"
  }
}

注意增加如上两个配置和http-proxy和https-proxy

(2)安装Docker

bash 复制代码
yum -y install yum-utils device-mapper-persistent-data lvm2
yum -y install docker-ce
systemctl daemon-reload

(3)重启Docker

bash 复制代码
[root@dev ~]# systemctl restart docker
[root@dev ~]# 

(4)现在可以搜索镜像了

bash 复制代码
[root@dev ~]# docker search nginx
NAME                                     DESCRIPTION                                      STARS     OFFICIAL
nginx                                    Official build of Nginx.                         20812     [OK]
nginx/nginx-ingress                      NGINX and  NGINX Plus Ingress Controllers fo...   107       
nginx/nginx-prometheus-exporter          NGINX Prometheus Exporter for NGINX and NGIN...   50        
nginx/unit                               This repository is retired, use the Docker o...   66        
nginx/nginx-ingress-operator             NGINX Ingress Operator for NGINX and NGINX P...   2         
nginx/nginx-quic-qns                     NGINX QUIC interop                               1         
nginx/nginxaas-loadbalancer-kubernetes                                                    1         
nginx/unit-preview                       Unit preview features                            0         
bitnami/nginx                            Bitnami container image for NGINX                198       
ubuntu/nginx                             Nginx, a high-performance reverse proxy & we...   129       
bitnamicharts/nginx                      Bitnami Helm chart for NGINX Open Source         0         
kasmweb/nginx                            An Nginx image based off nginx:alpine and in...   8         
rancher/nginx                                                                             2         
linuxserver/nginx                        An Nginx container, brought to you by LinuxS...   230       
dtagdevsec/nginx                         T-Pot Nginx                                      0         
paketobuildpacks/nginx                                                                    0         
vmware/nginx                                                                              2         
gluufederation/nginx                      A customized NGINX image containing a consu...   1         
chainguard/nginx                         Build, ship and run secure software with Cha...   4         
intel/nginx                                                                               0         
droidwiki/nginx                                                                           0         
antrea/nginx                             Nginx server used for Antrea e2e testing         0         
circleci/nginx                           This image is for internal use                   2         
docksal/nginx                            Nginx service image for Docksal                  0         
corpusops/nginx                          https://github.com/corpusops/docker-images/      1         
[root@dev ~]# 

(5)创建实例

bash 复制代码
docker run --name nginx --privileged=true --restart=always -d -p 80:80 -v /home/docker/nginx/html:/usr/share/nginx/html:ro nginx:latest

# 带配置文件,注意先新建配置文件/home/docker/nginx/conf/nginx.conf
docker run --name nginx --privileged=true --restart=always -d -p 80:80 -v /home/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro -v /home/docker/nginx/html:/usr/share/nginx/html:ro nginx:latest

/home/docker/nginx/conf/nginx.conf配置文件内容如下:

bash 复制代码
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    client_max_body_size 200M;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        #add_header 'Access-Control-Allow-Origin' *;
        #add_header 'Access-Control-Allow-Credentials' 'true';
        #add_header 'Access-Control-Allow-Methods' *;
        #add_header 'Access-Control-Allow-Headers' *;

        location / {
            #root   html;
            root    /usr/share/nginx/html;
            index  index.html index.htm;
        }
        
        location /test {
            proxy_pass http://localhost:82/test/abc/;
        }
        
        location /test/files {
           proxy_pass http://192.168.31.2;
        }

        location /api/ {
            proxy_pass http://192.168.31.2:9001/;
        }
        
        location /test {
            # proxy_pass   http://192.168.31.2:8045;
            if ($arg_token) {
                rewrite ^/test/(.*)$ http://192.168.31.2:8080/test2/$1 permanent;
            }
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    # server {
    #     listen       82;
    #     server_name  localhost;
        
    #     location / {
    #         root   html;
    #         index  index.html index.htm;
    #     }

    #     #error_page  404              /404.html;

    #     # redirect server error pages to the static page /50x.html
    #     #
    #     error_page   500 502 503 504  /50x.html;
    #     location = /50x.html {
    #         root   html;
    #     }
    # }
}

其它

(1)移除历史Docker

bash 复制代码
# 更新系统并清理旧版本 Docker
sudo yum update -y
sudo yum remove docker* -y

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
rm -rf /etc/systemd/system/docker.service.d
rm -rf /var/lib/docker
rm -rf /var/run/docker

(2)安装历史版本

bash 复制代码
yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.9-3.el7.x86_64.rpm

(3)放开防火墙

bash 复制代码
firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload
相关推荐
闲云自留地3 小时前
K8s 的记忆大脑!ETCD 集群部署、etcdctl 命令与备份恢复全通关
容器·kubernetes·etcd
讯捷蓝达3 小时前
戴尔R720xd服务器卡死在 “Configuring Memory...Done“,换了内存还是卡?问题根本不在内存
运维·服务器
爱和冰阔落5 小时前
【Linux网络】TCP 服务器如何并发处理多个客户端?从 fork、僵尸进程到双重 fork
linux·运维·服务器·网络
lisanmengmeng6 小时前
alertmanger 标签 rules 打上分组标签
linux·运维·服务器
Android系统攻城狮7 小时前
Linux FFmpeg深度解析之av_write_frame调用流程与实战(三十三)
linux·运维·服务器·ffmpeg·音视频进阶·ffmpeg音视频
上火的金鱼妹7 小时前
k8s生产实际问题排查(网关,数据库读写等)
运维·服务器
孙克旭_7 小时前
k8s基础组件与创建资源
运维·docker·容器·kubernetes
孙克旭_7 小时前
云原生基础之Containerd容器运行时
运维·云原生
分布式存储与RustFS7 小时前
RustFS 自建对象存储实战目录:110 篇按场景分类(持续更新)
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
无忧_wy7 小时前
MoneyPrinterTurbo 自动化视频生成实战指南
运维·人工智能·自动化·音视频