欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > Docker设置代理

Docker设置代理

2025/6/23 8:24:06 来源:https://blog.csdn.net/Angushine/article/details/148340502  浏览:    关键词:Docker设置代理

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

[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

yum -y install yum-utils device-mapper-persistent-data lvm2
yum -y install docker-ce
systemctl daemon-reload

(3)重启Docker

[root@dev ~]# systemctl restart docker
[root@dev ~]# 

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

[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)创建实例

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配置文件内容如下:

#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

# 更新系统并清理旧版本 Docker
sudo yum update -y
sudo yum remove docker* -yyum 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)安装历史版本

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

(3)放开防火墙

firewall-cmd --zone=public --add-port=80/tcp --permanent && firewall-cmd --reload

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词