当前位置: 首页 > news >正文

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
http://www.xdnf.cn/news/734671.html

相关文章:

  • ros2工程在普通用户下正常编译但root下编译无法成功也不会自动停止
  • RAG混合检索:倒数秩融合RRF算法
  • 零硬件成本玩转嵌入式通信!嵌入式仿真实验教学平台解锁STM8S串口黑科技
  • 对COM组件的调用返回错误 HRESULT E_FAIL
  • Linux操作系统之进程(四):命令行参数与环境变量
  • 统计C盘各种扩展名文件大小总和及数量的PowerShell脚本
  • << C程序设计语言第2版 >> 练习 1-23 删除C语言程序中所有的注释语句
  • Python基于Django的校园打印预约系统(附源码,文档说明)
  • 天拓四方工业互联网平台赋能:地铁电力配电室综合监控与无人巡检,实现效益与影响的双重显著提升
  • URL编码次数差异分析:一次编码 vs 二次编码
  • 【动手学深度学习】2.4. 微积分
  • Python中openpyxl库的基础解析与代码实例
  • NIO----JAVA
  • API:解锁网络世界的无限可能
  • Leetcode 340. 至多包含 K 个不同字符的最长子串
  • Java并发
  • [特殊字符] 超强 Web React版 PDF 阅读器!支持分页、缩放、旋转、全屏、懒加载、缩略图!
  • Elasticsearch的写入流程介绍
  • vscode实时预览编辑markdown
  • 树莓派安装openwrt搭建软路由(ImmortalWrt固件方案)
  • <3>, 常用控件
  • wheelgames
  • C++17新特性 类型推导
  • 虚拟化数据恢复—XenServer虚拟机虚拟磁盘文件丢失的数据恢复案例
  • 集成测试 maestro-我的第一个flow以及第一次云端测试
  • React和原生事件的区别
  • π0-FAST-针对VLA模型的高效动作token化技术-2025.1.16-开源
  • 使用 Fetch + Streams 处理流式响应(Streaming Response)
  • Odoo OWL 框架深度研究(VIP10万字版)
  • 特伦斯 S75 电钢琴:重构演奏美学的极致表达