docker代理设置ssl证书_docker - 设置HTTP/HTTPS 代理
1、設(shè)置代理原因
因公司安全限制,所有外網(wǎng)需配置代理后才可上網(wǎng),但是因為宿主機(jī)上設(shè)置過代理,并未太過多注意此問題,之后run時報如下錯誤:
# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
在網(wǎng)上搜索過一番之后,發(fā)現(xiàn):如果在docker 宿主機(jī)上設(shè)置了代理(HTTP、HTTPS)之后,在docker daemon 啟動的時候,也要相應(yīng)的告知 daemon,使用代理來訪問internet!!
2、解決方案
盡管docker daemon 的配置可以兩種方式來實現(xiàn):
2.1通過daemon.json文件來修改
2.2通過覆蓋docker.service來實現(xiàn)
但是對于代理的配置,目前為止(docker 17.06)我們只能使用第二個方案。 具體的步驟如下:
創(chuàng)建docker.service目錄
mkdir -p /etc/systemd/system/docker.service.d
創(chuàng)建HTTP&HTTPS代理文件
# cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment=HTTP_PROXY=xxx.xxx.xxx.xxx:8080 NO_PROXY=localhost,127.0.0.1
[root@localhost ~]# cat /etc/systemd/system/docker.service.d/https-proxy.conf
[Service]
Environment=HTTPS_PROXY=xxx.xxx.xxx.xxx:8080 NO_PROXY=localhost,127.0.0.1
解析:
主要是兩點(diǎn)內(nèi)容:
① ?HTTPS_PROXY將它的值對應(yīng)到您所希望設(shè)置的代理服務(wù)地址和端口(例如:?HTTPS_PROXY=https://proxy.example.com:443),我這里為了保護(hù)隱私,就用xxx代替.
② ?NO_PROXY?意味著某些情況下我們不需要使用HTTPS代理來訪問,一般這就配置私有倉庫的路徑(例如:NO_PROXY=localhost,127.0.0.1,mydocker-registry.com:5000)
3、完成修改后保存/刷新
# systemctl daemon-reload
# systemctl restart docker
4、查看修改結(jié)果
# docker run hello-world
Unable to find image 'hello-world:latest'locally
latest: Pullingfrom library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer imagefor hello-world:latest
Hellofrom Docker!This message shows that your installation appears to be working correctly.
To generatethismessage, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image fromthe Docker Hub.
(amd64)3. The Docker daemon created a new container fromthat image which runs the
executable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
Totrysomething more ambitious, you can run an Ubuntu container with:
$ docker run-it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
5、重新登錄docker hub
docker login -u xxx -p xxx
login Suceeded
可以看到已經(jīng)成功解決問題!
參考自官方文檔:https://docs.docker.com/engine/admin/systemd/
總結(jié)
以上是生活随笔為你收集整理的docker代理设置ssl证书_docker - 设置HTTP/HTTPS 代理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 花样机模板电脑CAD免费打板转格式软件P
- 下一篇: 利用keras实现孪生网络中的权值共享