Skip to content

Instantly share code, notes, and snippets.

@alphamarket
Last active June 27, 2024 17:42
Show Gist options
  • Save alphamarket/404fb8dda86edfe204ab38719379833a to your computer and use it in GitHub Desktop.
Save alphamarket/404fb8dda86edfe204ab38719379833a to your computer and use it in GitHub Desktop.
How to make docker pull using a socks5 proxy

Create the config file:

mkdir -p /etc/systemd/system/docker.service.d && \
vi /etc/systemd/system/docker.service.d/http-proxy.conf

Put up the configs:

[Service]
Environment="ALL_PROXY=socks5h://127.0.0.1:1080"
Environment="HTTP_PROXY=socks5h://127.0.0.1:1080"
Environment="HTTPS_PROXY=socks5h://127.0.0.1:1080"

Flush changes:

sudo systemctl daemon-reload

Verify that the configuration has been loaded:

sudo systemctl show --property Environment docker

Restart Docker:

sudo systemctl restart docker
@JKBGIT1
Copy link

JKBGIT1 commented Jun 4, 2024

Hello, I'm running Docker Engine - Community 26.1.3 on Ubuntu 22.04. I used dante-server 1.4.2 as a SOCKS proxy. It is listening on 127.0.0.1:1080. Using the proxy in Docker works perfectly when I set it up as socks5://127.0.0.1:1080, but when I switch to socks5h://127.0.0.1:1080 I get the following error when pulling images.

Error response from daemon: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp: lookup socks5h on 127.0.0.53:53: server misbehaving

This is the output of tcpdump -i any -n port 53 after running docker pull hello-world. Seems like it is using socks5h as the hostname of a machine, whereas the hostname is completely different.

listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
07:54:50.387182 lo    In  IP 127.0.0.1.41742 > 127.0.0.53.53: 43627+ [1au] AAAA? docker.io. (38)
07:54:50.387245 lo    In  IP 127.0.0.1.59556 > 127.0.0.53.53: 33029+ [1au] A? docker.io. (38)
07:54:50.387556 eth0  Out IP 10.0.2.6.36336 > 168.63.129.16.53: 18077+ [1au] AAAA? docker.io. (38)
07:54:50.387629 eth0  Out IP 10.0.2.6.34951 > 168.63.129.16.53: 6533+ [1au] A? docker.io. (38)
07:54:50.389364 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.34951: 6533 3/0/1 A 3.224.227.198, A 44.219.3.189, A 44.193.181.103 (86)
07:54:50.389459 lo    In  IP 127.0.0.53.53 > 127.0.0.1.59556: 33029 3/0/1 A 3.224.227.198, A 44.219.3.189, A 44.193.181.103 (86)
07:54:50.389822 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.36336: 18077 3/0/1 AAAA 2600:1f18:2148:bc02:4f78:625e:1ac1:714c, AAAA 2600:1f18:2148:bc00:a518:1574:fea8:ccdb, AAAA 2600:1f18:2148:bc01:2822:9e2a:c82a:af0 (122)
07:54:50.389882 lo    In  IP 127.0.0.53.53 > 127.0.0.1.41742: 43627 3/0/1 AAAA 2600:1f18:2148:bc02:4f78:625e:1ac1:714c, AAAA 2600:1f18:2148:bc00:a518:1574:fea8:ccdb, AAAA 2600:1f18:2148:bc01:2822:9e2a:c82a:af0 (122)
07:54:50.390210 lo    In  IP 127.0.0.1.43850 > 127.0.0.53.53: 56498+ [1au] AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390314 lo    In  IP 127.0.0.1.51804 > 127.0.0.53.53: 7787+ [1au] A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390451 eth0  Out IP 10.0.2.6.60064 > 168.63.129.16.53: 65014+ [1au] AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390531 eth0  Out IP 10.0.2.6.37605 > 168.63.129.16.53: 17167+ [1au] A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.392981 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.60064: 65014 NXDomain 0/1/1 (176)
07:54:50.393071 eth0  Out IP 10.0.2.6.60064 > 168.63.129.16.53: 65014+ AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (79)
07:54:50.393465 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.37605: 17167 NXDomain 0/1/1 (176)
07:54:50.393513 eth0  Out IP 10.0.2.6.37605 > 168.63.129.16.53: 17167+ A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (79)
07:54:50.396061 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.37605: 17167 NXDomain 0/1/0 (165)
07:54:50.396185 lo    In  IP 127.0.0.53.53 > 127.0.0.1.51804: 7787 NXDomain 0/1/1 (176)
07:54:50.398918 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.60064: 65014 NXDomain 0/1/0 (165)
07:54:50.399081 lo    In  IP 127.0.0.53.53 > 127.0.0.1.43850: 56498 NXDomain 0/1/1 (176)
07:54:50.399220 lo    In  IP 127.0.0.1.53898 > 127.0.0.53.53: 57864+ [1au] AAAA? socks5h. (36)
07:54:50.399306 lo    In  IP 127.0.0.1.54697 > 127.0.0.53.53: 41244+ [1au] A? socks5h. (36)
07:54:50.399388 lo    In  IP 127.0.0.53.53 > 127.0.0.1.53898: 57864 ServFail* 0/0/1 (36)
07:54:50.399427 lo    In  IP 127.0.0.53.53 > 127.0.0.1.54697: 41244 ServFail* 0/0/1 (36)
07:54:50.399617 lo    In  IP 127.0.0.1.49826 > 127.0.0.53.53: 45852+ [1au] A? socks5h. (36)
07:54:50.399656 lo    In  IP 127.0.0.1.42823 > 127.0.0.53.53: 40535+ [1au] AAAA? socks5h. (36)
07:54:50.399713 lo    In  IP 127.0.0.53.53 > 127.0.0.1.49826: 45852 ServFail* 0/0/1 (36)
07:54:50.399751 lo    In  IP 127.0.0.53.53 > 127.0.0.1.42823: 40535 ServFail* 0/0/1 (36)

@yanxin152133
Copy link

Hello, I'm running Docker Engine - Community 26.1.3 on Ubuntu 22.04. I used dante-server 1.4.2 as a SOCKS proxy. It is listening on 127.0.0.1:1080. Using the proxy in Docker works perfectly when I set it up as socks5://127.0.0.1:1080, but when I switch to socks5h://127.0.0.1:1080 I get the following error when pulling images.

Error response from daemon: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp: lookup socks5h on 127.0.0.53:53: server misbehaving

This is the output of tcpdump -i any -n port 53 after running docker pull hello-world. Seems like it is using socks5h as the hostname of a machine, whereas the hostname is completely different.

listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
07:54:50.387182 lo    In  IP 127.0.0.1.41742 > 127.0.0.53.53: 43627+ [1au] AAAA? docker.io. (38)
07:54:50.387245 lo    In  IP 127.0.0.1.59556 > 127.0.0.53.53: 33029+ [1au] A? docker.io. (38)
07:54:50.387556 eth0  Out IP 10.0.2.6.36336 > 168.63.129.16.53: 18077+ [1au] AAAA? docker.io. (38)
07:54:50.387629 eth0  Out IP 10.0.2.6.34951 > 168.63.129.16.53: 6533+ [1au] A? docker.io. (38)
07:54:50.389364 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.34951: 6533 3/0/1 A 3.224.227.198, A 44.219.3.189, A 44.193.181.103 (86)
07:54:50.389459 lo    In  IP 127.0.0.53.53 > 127.0.0.1.59556: 33029 3/0/1 A 3.224.227.198, A 44.219.3.189, A 44.193.181.103 (86)
07:54:50.389822 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.36336: 18077 3/0/1 AAAA 2600:1f18:2148:bc02:4f78:625e:1ac1:714c, AAAA 2600:1f18:2148:bc00:a518:1574:fea8:ccdb, AAAA 2600:1f18:2148:bc01:2822:9e2a:c82a:af0 (122)
07:54:50.389882 lo    In  IP 127.0.0.53.53 > 127.0.0.1.41742: 43627 3/0/1 AAAA 2600:1f18:2148:bc02:4f78:625e:1ac1:714c, AAAA 2600:1f18:2148:bc00:a518:1574:fea8:ccdb, AAAA 2600:1f18:2148:bc01:2822:9e2a:c82a:af0 (122)
07:54:50.390210 lo    In  IP 127.0.0.1.43850 > 127.0.0.53.53: 56498+ [1au] AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390314 lo    In  IP 127.0.0.1.51804 > 127.0.0.53.53: 7787+ [1au] A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390451 eth0  Out IP 10.0.2.6.60064 > 168.63.129.16.53: 65014+ [1au] AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390531 eth0  Out IP 10.0.2.6.37605 > 168.63.129.16.53: 17167+ [1au] A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.392981 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.60064: 65014 NXDomain 0/1/1 (176)
07:54:50.393071 eth0  Out IP 10.0.2.6.60064 > 168.63.129.16.53: 65014+ AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (79)
07:54:50.393465 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.37605: 17167 NXDomain 0/1/1 (176)
07:54:50.393513 eth0  Out IP 10.0.2.6.37605 > 168.63.129.16.53: 17167+ A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (79)
07:54:50.396061 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.37605: 17167 NXDomain 0/1/0 (165)
07:54:50.396185 lo    In  IP 127.0.0.53.53 > 127.0.0.1.51804: 7787 NXDomain 0/1/1 (176)
07:54:50.398918 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.60064: 65014 NXDomain 0/1/0 (165)
07:54:50.399081 lo    In  IP 127.0.0.53.53 > 127.0.0.1.43850: 56498 NXDomain 0/1/1 (176)
07:54:50.399220 lo    In  IP 127.0.0.1.53898 > 127.0.0.53.53: 57864+ [1au] AAAA? socks5h. (36)
07:54:50.399306 lo    In  IP 127.0.0.1.54697 > 127.0.0.53.53: 41244+ [1au] A? socks5h. (36)
07:54:50.399388 lo    In  IP 127.0.0.53.53 > 127.0.0.1.53898: 57864 ServFail* 0/0/1 (36)
07:54:50.399427 lo    In  IP 127.0.0.53.53 > 127.0.0.1.54697: 41244 ServFail* 0/0/1 (36)
07:54:50.399617 lo    In  IP 127.0.0.1.49826 > 127.0.0.53.53: 45852+ [1au] A? socks5h. (36)
07:54:50.399656 lo    In  IP 127.0.0.1.42823 > 127.0.0.53.53: 40535+ [1au] AAAA? socks5h. (36)
07:54:50.399713 lo    In  IP 127.0.0.53.53 > 127.0.0.1.49826: 45852 ServFail* 0/0/1 (36)
07:54:50.399751 lo    In  IP 127.0.0.53.53 > 127.0.0.1.42823: 40535 ServFail* 0/0/1 (36)

Have you solved this problem?

@yanxin152133
Copy link

Hello, I'm running Docker Engine - Community 26.1.3 on Ubuntu 22.04. I used dante-server 1.4.2 as a SOCKS proxy. It is listening on 127.0.0.1:1080. Using the proxy in Docker works perfectly when I set it up as socks5://127.0.0.1:1080, but when I switch to socks5h://127.0.0.1:1080 I get the following error when pulling images.

Error response from daemon: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp: lookup socks5h on 127.0.0.53:53: server misbehaving

This is the output of tcpdump -i any -n port 53 after running docker pull hello-world. Seems like it is using socks5h as the hostname of a machine, whereas the hostname is completely different.

listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
07:54:50.387182 lo    In  IP 127.0.0.1.41742 > 127.0.0.53.53: 43627+ [1au] AAAA? docker.io. (38)
07:54:50.387245 lo    In  IP 127.0.0.1.59556 > 127.0.0.53.53: 33029+ [1au] A? docker.io. (38)
07:54:50.387556 eth0  Out IP 10.0.2.6.36336 > 168.63.129.16.53: 18077+ [1au] AAAA? docker.io. (38)
07:54:50.387629 eth0  Out IP 10.0.2.6.34951 > 168.63.129.16.53: 6533+ [1au] A? docker.io. (38)
07:54:50.389364 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.34951: 6533 3/0/1 A 3.224.227.198, A 44.219.3.189, A 44.193.181.103 (86)
07:54:50.389459 lo    In  IP 127.0.0.53.53 > 127.0.0.1.59556: 33029 3/0/1 A 3.224.227.198, A 44.219.3.189, A 44.193.181.103 (86)
07:54:50.389822 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.36336: 18077 3/0/1 AAAA 2600:1f18:2148:bc02:4f78:625e:1ac1:714c, AAAA 2600:1f18:2148:bc00:a518:1574:fea8:ccdb, AAAA 2600:1f18:2148:bc01:2822:9e2a:c82a:af0 (122)
07:54:50.389882 lo    In  IP 127.0.0.53.53 > 127.0.0.1.41742: 43627 3/0/1 AAAA 2600:1f18:2148:bc02:4f78:625e:1ac1:714c, AAAA 2600:1f18:2148:bc00:a518:1574:fea8:ccdb, AAAA 2600:1f18:2148:bc01:2822:9e2a:c82a:af0 (122)
07:54:50.390210 lo    In  IP 127.0.0.1.43850 > 127.0.0.53.53: 56498+ [1au] AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390314 lo    In  IP 127.0.0.1.51804 > 127.0.0.53.53: 7787+ [1au] A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390451 eth0  Out IP 10.0.2.6.60064 > 168.63.129.16.53: 65014+ [1au] AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.390531 eth0  Out IP 10.0.2.6.37605 > 168.63.129.16.53: 17167+ [1au] A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (90)
07:54:50.392981 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.60064: 65014 NXDomain 0/1/1 (176)
07:54:50.393071 eth0  Out IP 10.0.2.6.60064 > 168.63.129.16.53: 65014+ AAAA? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (79)
07:54:50.393465 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.37605: 17167 NXDomain 0/1/1 (176)
07:54:50.393513 eth0  Out IP 10.0.2.6.37605 > 168.63.129.16.53: 17167+ A? socks5h.vpflbhrunv3e3bfslny0o5zjmh.frax.internal.cloudapp.net. (79)
07:54:50.396061 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.37605: 17167 NXDomain 0/1/0 (165)
07:54:50.396185 lo    In  IP 127.0.0.53.53 > 127.0.0.1.51804: 7787 NXDomain 0/1/1 (176)
07:54:50.398918 eth0  In  IP 168.63.129.16.53 > 10.0.2.6.60064: 65014 NXDomain 0/1/0 (165)
07:54:50.399081 lo    In  IP 127.0.0.53.53 > 127.0.0.1.43850: 56498 NXDomain 0/1/1 (176)
07:54:50.399220 lo    In  IP 127.0.0.1.53898 > 127.0.0.53.53: 57864+ [1au] AAAA? socks5h. (36)
07:54:50.399306 lo    In  IP 127.0.0.1.54697 > 127.0.0.53.53: 41244+ [1au] A? socks5h. (36)
07:54:50.399388 lo    In  IP 127.0.0.53.53 > 127.0.0.1.53898: 57864 ServFail* 0/0/1 (36)
07:54:50.399427 lo    In  IP 127.0.0.53.53 > 127.0.0.1.54697: 41244 ServFail* 0/0/1 (36)
07:54:50.399617 lo    In  IP 127.0.0.1.49826 > 127.0.0.53.53: 45852+ [1au] A? socks5h. (36)
07:54:50.399656 lo    In  IP 127.0.0.1.42823 > 127.0.0.53.53: 40535+ [1au] AAAA? socks5h. (36)
07:54:50.399713 lo    In  IP 127.0.0.53.53 > 127.0.0.1.49826: 45852 ServFail* 0/0/1 (36)
07:54:50.399751 lo    In  IP 127.0.0.53.53 > 127.0.0.1.42823: 40535 ServFail* 0/0/1 (36)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment