在新机器安装 Docker 以及代理配置
步骤
在 Fedora 上使用 Yum 安装 Docker 时,需要先添加 Fedora 的 Docker repo 源,有时可能因为网络原因无法成功。
这时可以配置 /etc/enviroment
文件,让 yum 走代理网络:
在
/etc/enviroment
添加如下内容:
1http_proxy=127.0.0.1:1234
2https_proxy=127.0.0.1:1234
添加 Docker Yum 源:
1sudo yum-config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
查看当前系统添加的所有 Yum 源:
1sudo yum repolist
2# 结果
3repo id repo name
4docker-ce-stable Docker CE Stable - x86_64
5fedora Fedora 40 - x86_64
6fedora-cisco-openh264 Fedora 40 openh264 (From Cisco) - x86_64
7updates Fedora 40 - x86_64 - Updates
安装 Docker :
1sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
启动 Docker 服务:
1sudo systemctl start docker
配置 Docker pull 代理:
1sudo mkdir -p /etc/systemd/system/docker.service.d
2sudo touch /etc/systemd/system/docker.service.d/proxy.conf
3
4# 在其中写入如下配置:
5[Service]
6Environment="HTTP_PROXY=http://127.0.0.1:1234/"
7Environment="HTTPS_PROXY=http://127.0.0.1:1234/"
8Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
重启 systemctl 以及 Docker:
1sudo systemctl daemon-reload
2sudo systemctl restart docker
测试 hello-world :
1sudo docker run hello-world
1结果:
2
3Unable to find image 'hello-world:latest' locally
4latest: Pulling from library/hello-world
5c1ec31eb5944: Pull complete
6Digest: sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6
7Status: Downloaded newer image for hello-world:latest
8
9Hello from Docker!
10This message shows that your installation appears to be working correctly.
11
12To generate this message, Docker took the following steps:
13 1. The Docker client contacted the Docker daemon.
14 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
15 (amd64)
16 3. The Docker daemon created a new container from that image which runs the
17 executable that produces the output you are currently reading.
18 4. The Docker daemon streamed that output to the Docker client, which sent it
19 to your terminal.
20
21To try something more ambitious, you can run an Ubuntu container with:
22 $ docker run -it ubuntu bash
23
24Share images, automate workflows, and more with a free Docker ID:
25 https://hub.docker.com/
26
27For more examples and ideas, visit:
28 https://docs.docker.com/get-started/
设置 Docker 开机自启动:
1sudo systemctl enable docker
将普通用户添加进 Docker 组:
1sudo usermod -aG docker junsircoding
2
3# 重启
参考资料
Docker的三种网络代理配置:https://note.qidong.name/2020/05/docker-proxy/