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
相关推荐
tuokuac5 小时前
docker中nginx配置报错解决
linux·运维·服务器
Joren的学习记录6 小时前
【Linux运维大神系列】docker详解(四)
linux·运维·docker
Elastic 中国社区官方博客7 小时前
让我们把这个 expense 工具从 n8n 迁移到 Elastic One Workflow
大数据·运维·elasticsearch·搜索引擎·ai·信息可视化·全文检索
( •̀∀•́ )9208 小时前
GitHub Actions SSH 部署密钥
运维·ssh·github
louqle8 小时前
docker基本知识及常用命令汇总
运维·docker·容器
学烹饪的小胡桃8 小时前
【运维学习】实时性能监控工具 WGCLOUD v3.6.2 更新介绍
linux·运维·服务器·学习·工单系统
叫致寒吧8 小时前
Docker
运维·docker·容器
杨浦老苏9 小时前
现代流媒体聚合播放器冬瓜TV MAX
docker·群晖·多媒体
白露与泡影9 小时前
使用systemd,把服务装进 Linux 心脏里~
linux·运维·python
l1t10 小时前
用docker安装oracle 19c
运维·数据库·docker·oracle·容器