docker_practice/advanced_network/http_https_proxy.md

75 lines
2.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# HTTP/HTTPS
使Docker使 HTTP/HTTPS 使
## dockerd
"docker pull" dockerd dockerd systemd "docker pull" 使 HTTP/HTTPS systemd
- dockerd
```
sudo mkdir -p /etc/systemd/system/docker.service.d
```
- dockerd HTTP/HTTPS /etc/systemd/system/docker.service.d/http-proxy.conf
```
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
```
- docker
```
sudo systemctl daemon-reload
sudo systemctl restart docker
```
## docker
使 HTTP/HTTPS docker
- docker ~/.docker/config.json
```
{
"proxies":
{
"default":
{
"httpProxy": "http://proxy.example.com:8080/",
"httpsProxy": "http://proxy.example.com:8080/",
"noProxy": "localhost,127.0.0.1,.example.com"
}
}
}
```
- "docker run"
| | docker run |
| -------- | ---------------- |
| HTTP_PROXY | --env HTTP_PROXY="http://proxy.example.com:8080/" |
| HTTPS_PROXY | --env HTTPS_PROXY="http://proxy.example.com:8080/" |
| NO_PROXY | --env NO_PROXY="localhost,127.0.0.1,.example.com" |
## docker build
使 HTTP/HTTPS "docker build" Dockerfile
- 使 "--build-arg" "docker build"
```
docker build \
--build-arg "HTTP_PROXY=http://proxy.example.com:8080/" \
--build-arg "HTTPS_PROXY=http://proxy.example.com:8080/" \
--build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" .
```
- Dockerfile
| | Dockerfile |
| -------- | ---------------- |
| HTTP_PROXY | ENV HTTP_PROXY="http://proxy.example.com:8080/" |
| HTTPS_PROXY | ENV HTTPS_PROXY="http://proxy.example.com:8080/" |
| NO_PROXY | ENV NO_PROXY="localhost,127.0.0.1,.example.com" |