Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 4b8890c

Browse files
authored
Merge pull request #639 from inoc603/proxy_doc
doc: user guide to use dfdaemon as http proxy for docker
2 parents aa49643 + 47a05d6 commit 4b8890c

File tree

2 files changed

+104
-64
lines changed

2 files changed

+104
-64
lines changed

docs/user_guide/docker_proxy.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Use Dfdaemon as HTTP Proxy for Docker Daemon
2+
3+
Currently, docker doesn't support private registries with `registry-mirrors`,
4+
in order to do so, we need to use HTTP proxy for docker daemon.
5+
6+
To use dfdaemon as HTTP proxy, first you need to add a proxy rule in
7+
`/etc/dragonfly/dfdaemon.yml`:
8+
9+
```yaml
10+
proxies:
11+
- regx: blobs/sha256:.*
12+
```
13+
14+
This will proxy all requests for image layers with dfget.
15+
16+
By default, only HTTP requests are proxied with dfget. If you're using an HTTPS
17+
enabled private registry, you need to add the following HTTPS configuration to
18+
`/etc/dragonfly/dfdaemon.yml`:
19+
20+
```yaml
21+
hijack_https:
22+
cert: df.crt
23+
key: df.key
24+
hosts:
25+
- regx: your.private.registry
26+
```
27+
28+
If your registry uses a self-signed certificate, you can either choose to
29+
ignore the certificate error with:
30+
31+
```yaml
32+
hosts:
33+
- regx: your.private.registry
34+
insecure: true
35+
```
36+
37+
Or provide a certificate with:
38+
39+
```yaml
40+
hosts:
41+
- regx: your.private.registry
42+
certs: ["server.crt"]
43+
```
44+
45+
You can get the certificate of your server with:
46+
47+
```
48+
openssl x509 -in <(openssl s_client -showcerts -servername xxx -connect xxx:443 -prexit 2>/dev/null)
49+
```
50+
51+
Add your private registry to `insecure-registries` in
52+
`/etc/docker/daemon.json`, in order to ignore the certificate error:
53+
54+
```json
55+
{
56+
"insecure-registries": ["your.private.registry"]
57+
}
58+
```
59+
60+
Set dfdaemon as HTTP_PROXY and HTTPS_PROXY for docker daemon in
61+
`/etc/systemd/system/docker.service.d/http-proxy.conf`:
62+
63+
```
64+
[Service]
65+
Environment="HTTP_PROXY=http://127.0.0.1:65001"
66+
Environment="HTTPS_PROXY=http://127.0.0.1:65001"
67+
```
68+
69+
Read [Control Docker with systemd](https://docs.docker.com/config/daemon/systemd/#httphttps-proxy) for more details. If you're not running docker daemon with systemd, you need to set the environment variables manually.
70+
71+
Finally you can restart docker daemon and pull images as you normally would.
72+
73+
More details on dfdaemon's proxy configuration can be found
74+
[here](proxy.md).

docs/user_guide/proxy.md

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,50 @@
11
# Use dfdaemon as an HTTP proxy
22

3-
Dfdaemon can be used as an HTTP proxy to speed up image pulling from any registry
4-
as well as general HTTP downloads.
3+
## Prerequisites
54

6-
Please first ensure that you know how to install and run [supernode](install_server.md)
7-
and [dfdaemon](install_client.md).
5+
You need to first install and configure [supernode](install_server.md) and [dfdaemon](install_client.md).
86

9-
**HTTPS support is currently very limited. All HTTPS request will be tunneled
10-
directly, without dfget.**
7+
## Proxy Configuration
118

12-
## Proxy rule configuration
13-
14-
Proxy rules are configured in `/etc/dragonfly/dfdaemon.yml`. For performance
15-
reason, dfdaemon will handle a request with the the first matching rule.
9+
Proxy rules are configured in `/etc/dragonfly/dfdaemon.yml`.
1610

1711
```yaml
12+
# Requests that match the regular expressions will be proxied with dfget,
13+
# otherwise they'll be proxied directly. Requests will be handled by the first
14+
# matching rule.
1815
proxies:
19-
# proxy requests directly, without dfget
16+
# proxy all http image layer download requests with dfget
17+
- regx: blobs/sha256:.*
18+
# proxy requests directly, without dfget
2019
- regx: no-proxy-reg
2120
direct: true
22-
# proxy all http image layer download requests with dfget
23-
- regx: blobs/sha256:.*
24-
# change http requests to some-registry to https, and proxy them with dfget
21+
# change http requests to some-registry to https, and proxy them with dfget
2522
- regx: some-registry/
2623
use_https: true
27-
```
28-
29-
## Download images
30-
31-
Add the following content to `/etc/dragonfly/dfdaemon.yml`.
32-
33-
```yaml
34-
proxies:
35-
# proxy all http image layer download requests with dfget
36-
- regx: blobs/sha256:.*
37-
```
38-
39-
Set HTTP_PROXY for docker daemon in `/etc/systemd/system/docker.service.d/http-proxy.conf`.
40-
`65001` is the default proxy port for dfdaemon.
41-
42-
```
43-
[Service]
44-
Environment="HTTP_PROXY=http://127.0.0.1:65001"
45-
```
4624

47-
Set your registry as insecure in `/etc/docker/daemon.json`
48-
49-
```json
50-
{
51-
"insecure-registries": [ "your.registry" ]
52-
}
25+
# If an https request's host matches any of the hijacking rules, dfdaemon will
26+
# decrypt the request with given key pair and proxy it with the proxy rules.
27+
hijack_https:
28+
cert: df.crt
29+
key: df.key
30+
hosts:
31+
# match hosts by regular expressions. certificate will be validated normally
32+
- regx: host-1
33+
# ignore certificate errors
34+
- regx: host-2
35+
insecure: true
36+
# use the given certificate for validation
37+
- regx: host-3
38+
certs: ["server.crt"]
5339
```
5440
55-
Start dfdaemon and restart docker daemon.
41+
## Usage
5642
57-
```
58-
systemctl restart docker
59-
```
43+
You can use dfdaemon like any other HTTP proxy. For example on linux and
44+
macOS, you can use the `HTTP_PROXY` or `HTTPS_PROXY` environment variables.
6045

61-
Pull an image to see if it works. For registries that are not configured
62-
insecure, you can still pull image from it, but dfdaemon will not be able to
63-
speed up your downloads with dfget.
46+
## Get the Certificate of Your Server
6447

6548
```
66-
docker pull nginx
67-
docker pull your.registry/team/repo:tag
49+
openssl x509 -in <(openssl s_client -showcerts -servername xxx -connect xxx:443 -prexit 2>/dev/null)
6850
```
69-
70-
Then you can [check if your image is downloaded with dfget](../../FAQ.md#how-to-check-if-block-piece-is-distributed-among-dfgets-nodes).
71-
72-
## Download files
73-
74-
You can simply use `HTTP_PROXY` environment variable to let dfdaemon download
75-
requests that match the proxy rules. This works for any program that
76-
respects the `HTTP_PROXY` environment variable.
77-
78-
```
79-
HTTP_PROXY=http://127.0.0.1:65001 curl http://github.com
80-
```
81-
82-
HTTPS requests and requests that are not matched, will be proxied directly,
83-
and dragonfly is not able to speed up them.
84-

0 commit comments

Comments
 (0)