Skip to content

Commit 6dbce2f

Browse files
committed
Docker for Mac's Proxy GUI is a monster; avoid it by setting ENV directly in LinuxKit config
1 parent c224375 commit 6dbce2f

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

Diff for: Docker-for-Mac.md

+48-29
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,63 @@
1-
# Attention: issues for developer scenarios!
1+
# Attention: don't use Docker's own GUI to set the proxy!
22

3-
- beware: this will probably break your Docker for Mac install in more ways than one
4-
- docker for mac does bizarre stuff with proxies, affecting runtime and building of containers
5-
- you might run into https://github.com/docker/for-mac/issues/2467
6-
- building images is affected for sure; simple "FROM ubuntu; RUN apt update" fails
3+
- See https://github.com/docker/for-mac/issues/2467
4+
- In `Docker > Preferences`, in `Resources > Proxies`, make sure you're NOT using manual proxies
5+
- Use the hack below to set the environment var directly in LinuxKit
6+
- The issue is that setting it in the GUI affects containers too (!!!), and we don't want that in this scenario
7+
- If you actually need an upstream proxy (for company proxy etc) this will NOT work.
78

89
# Using a Docker Desktop for Mac as a client for the proxy
910

1011
First, know this is a MiTM, and could break with new Docker Desktop for Mac releases or during resets/reinstalls/upgrades.
1112

1213
These instructions tested on Mac OS Catalina, and:
13-
- Docker Desktop for Mac `2.5.0.0` (Stable) (which provides Docker `19.03`)
1414
- Docker Desktop for Mac `2.4.2.0` (Edge) (which provides Docker `20.10.0-beta1`)
15+
- Docker Desktop for Mac `2.5.0.0` (Stable) (which provides Docker `19.03`)
1516

1617
This assumes you have `docker-registry-proxy` running _somewhere else_, eg, on a different machine on your local network.
1718

1819
See the main [README.md](README.md) for instructions. (If you're trying to run both proxy and client on the same machine, see below).
1920

20-
For these examples I will assume it is successfully running on `http://192.168.1.2:3128/`
21-
22-
- Make sure you can access the proxy. On your Mac/Terminal (not Docker), run:
23-
```shell script
24-
# with wget...
25-
wget --quiet -O - "http://192.168.1.2:3128/"
26-
# ... or, with curl:
27-
curl "http://192.168.1.2:3128/"
28-
```
29-
- Make sure your Docker Desktop for Mac install is pristine like new, go into Troubleshoot > "Reset to Factory defaults".
30-
- Inject the CA certificates into the Docker install inside the HyperKit VM running LinuxKit that is used by Docker Desktop for Mac.
31-
To do that, we use a privileged container. `justincormack/nsenter1` does the job nicely:
32-
```shell script
33-
docker run -it --privileged --pid=host justincormack/nsenter1 /bin/bash -c "wget -O - http://192.168.1.2:3128/ca.crt | tee -a /containers/services/docker/lower/etc/ssl/certs/ca-certificates.crt"
34-
```
35-
- Go into `Docker > Preferences`, and set `Resources > Proxies` to
36-
- "Manual proxy configuration" to ON
37-
- HTTP proxy: `http://192.168.1.2:3128/`
38-
- HTTPS proxy: `http://192.168.1.2:3128/`
39-
- (Optional) I also recommend "Enable CLI experimental features" under "Experimental Features" (since I use `buildx` a lot)
40-
- Click button "Apply & Restart", wait for it to restart.
21+
We'll inject the CA certificates and the HTTPS_PROXY env into the Docker install inside the HyperKit VM running LinuxKit that is used by Docker Desktop for Mac.
22+
23+
To do that, we use a privileged container. `justincormack/nsenter1` does the job nicely.
24+
25+
First things first:
26+
27+
### 1) Factory Reset Docker Desktop for Mac...
28+
... or make sure it's pristine (just installed).
29+
30+
- Go into Troubleshoot > "Reset to Factory defaults"
31+
- it will take a while to reset/restart everything and require your password.
32+
33+
### 2) Inject config into Docker's VM
34+
35+
For these examples I will assume it is successfully running on `http://192.168.1.2:3128/` --
36+
change the `export DRP_PROXY` as appropriate. Do not include slashes.
37+
38+
Run these commands in your Mac terminal.
39+
40+
```bash
41+
set -e
42+
export DRP_PROXY="192.168.66.100:3129" # Format IP:port, change this
43+
wget -O - "http://${DRP_PROXY}/" # Make sure you can reach the proxy
44+
# Inject the CA certificate
45+
docker run -it --privileged --pid=host justincormack/nsenter1 \
46+
/bin/bash -c "wget -O - http://$DRP_PROXY/ca.crt \
47+
| tee -a /containers/services/docker/lower/etc/ssl/certs/ca-certificates.crt"
48+
49+
# Preserve original config.
50+
docker run -it --privileged --pid=host justincormack/nsenter1 /bin/bash -c "cp /containers/services/docker/config.json /containers/services/docker/config.json.orig"
51+
52+
# Inject the HTTPS_PROXY enviroment variable. I dare you find a better way.
53+
docker run -it --privileged --pid=host justincormack/nsenter1 /bin/bash -c "sed -ibeforedockerproxy -e 's/\"PATH=/\"HTTPS_PROXY=http:\/\/$DRP_PROXY\/\",\"PATH=/' /containers/services/docker/config.json"
54+
```
55+
56+
### 3) Restart, test.
57+
58+
- Restart Docker. (Quit & Open again, or just go into Preferences and give it more RAM, then Restart.)
4159
- Try a `docker pull` now. It should be using the proxy (watch the logs on the proxy server).
60+
- Test that no crazy proxy has been set: `docker run -it curlimages/curl:latest http://ifconfig.me` and `docker run -it curlimages/curl:latest https://ifconfig.me` both work.
4261
- Important: **push**es done with this configured will either not work, or use the auth you configured on the proxy, if any. Beware, and report back.
4362

4463

@@ -48,8 +67,8 @@ For these examples I will assume it is successfully running on `http://192.168.1
4867

4968
You need to pre-pull the proxy itself and `justincormack/nsenter1`.
5069

51-
Then set up the proxy server, and then follow the instructions above (without the Factory Reset).
70+
Follow the instructions above, but pre-pull after the Factory Reset.
5271

53-
Do NOT use 127.0.0.1, instead use your machine's local LAN IP address. (Hint: there's a good chance 192.168.64.1 is useable, due the the way Docker Desktop for Mac sets networking up).
72+
Do NOT use 127.0.0.1, instead use your machine's local LAN IP address.
5473

5574
Make sure to bring the proxy up after applying/restarting the Docker Engine.

0 commit comments

Comments
 (0)