The complete guide to set up a Docker proxy Last Update: Nov 5, 2024
There are three types of proxies that Docker can set up. Here is a summary for your quick reference.
Daemon Proxy The daemon proxy is used when pulling from or pushing to a registry.
For Mac , you can set the proxy for Docker Desktop in settings:
For Ubuntu , there are 2 steps:
Edit /etc/docker/daemon.json
Restart the daemon
For example, the daemon.json:
auto — arduino bash c cpp csharp css diff go graphql ini java javascript json kotlin less lua makefile markdown objectivec perl php php-template plaintext python python-repl r ruby rust scss shell sql swift typescript vbnet wasm xml yaml 1c abnf accesslog actionscript ada angelscript apache applescript arcade armasm asciidoc aspectj autohotkey autoit avrasm awk axapta basic bnf brainfuck cal capnproto ceylon clean clojure clojure-repl cmake coffeescript coq cos crmsh crystal csp d dart delphi django dns dockerfile dos dsconfig dts dust ebnf elixir elm erb erlang erlang-repl excel fix flix fortran fsharp gams gauss gcode gherkin glsl gml golo gradle groovy haml handlebars haskell haxe hsp http hy inform7 irpf90 isbl jboss-cli julia julia-repl lasso latex ldif leaf lisp livecodeserver livescript llvm lsl mathematica matlab maxima mel mercury mipsasm mizar mojolicious monkey moonscript n1ql nestedtext nginx nim nix node-repl nsis ocaml openscad oxygene parser3 pf pgsql pony powershell processing profile prolog properties protobuf puppet purebasic q qml reasonml rib roboconf routeros rsl ruleslanguage sas scala scheme scilab smali smalltalk sml sqf stan stata step21 stylus subunit taggerscript tap tcl thrift tp twig vala vbscript vbscript-html verilog vhdl vim wren x86asm xl xquery zephir {
"registry-mirrors" : ["https://example.com”],
"proxies" : {
"http-proxy" : "http://127.0.0.1:7890",
"https-proxy" : "http://127.0.0.1:7890",
"no-proxy" : "*.test.example.com,.example.org,127.0.0.0/8"
}
}
How to restart the daemon:
auto — arduino bash c cpp csharp css diff go graphql ini java javascript json kotlin less lua makefile markdown objectivec perl php php-template plaintext python python-repl r ruby rust scss shell sql swift typescript vbnet wasm xml yaml 1c abnf accesslog actionscript ada angelscript apache applescript arcade armasm asciidoc aspectj autohotkey autoit avrasm awk axapta basic bnf brainfuck cal capnproto ceylon clean clojure clojure-repl cmake coffeescript coq cos crmsh crystal csp d dart delphi django dns dockerfile dos dsconfig dts dust ebnf elixir elm erb erlang erlang-repl excel fix flix fortran fsharp gams gauss gcode gherkin glsl gml golo gradle groovy haml handlebars haskell haxe hsp http hy inform7 irpf90 isbl jboss-cli julia julia-repl lasso latex ldif leaf lisp livecodeserver livescript llvm lsl mathematica matlab maxima mel mercury mipsasm mizar mojolicious monkey moonscript n1ql nestedtext nginx nim nix node-repl nsis ocaml openscad oxygene parser3 pf pgsql pony powershell processing profile prolog properties protobuf puppet purebasic q qml reasonml rib roboconf routeros rsl ruleslanguage sas scala scheme scilab smali smalltalk sml sqf stan stata step21 stylus subunit taggerscript tap tcl thrift tp twig vala vbscript vbscript-html verilog vhdl vim wren x86asm xl xquery zephir sudo systemctl daemon-reload
sudo systemctl restart docker
Building Proxy When building an image, for instance, if there is a RUN apt-install command in your Dockerfile and you need download something through a proxy, you will need a building proxy.
Usually, the proxy host is the host machine. If so, you can use host.docker.internal
.
auto — arduino bash c cpp csharp css diff go graphql ini java javascript json kotlin less lua makefile markdown objectivec perl php php-template plaintext python python-repl r ruby rust scss shell sql swift typescript vbnet wasm xml yaml 1c abnf accesslog actionscript ada angelscript apache applescript arcade armasm asciidoc aspectj autohotkey autoit avrasm awk axapta basic bnf brainfuck cal capnproto ceylon clean clojure clojure-repl cmake coffeescript coq cos crmsh crystal csp d dart delphi django dns dockerfile dos dsconfig dts dust ebnf elixir elm erb erlang erlang-repl excel fix flix fortran fsharp gams gauss gcode gherkin glsl gml golo gradle groovy haml handlebars haskell haxe hsp http hy inform7 irpf90 isbl jboss-cli julia julia-repl lasso latex ldif leaf lisp livecodeserver livescript llvm lsl mathematica matlab maxima mel mercury mipsasm mizar mojolicious monkey moonscript n1ql nestedtext nginx nim nix node-repl nsis ocaml openscad oxygene parser3 pf pgsql pony powershell processing profile prolog properties protobuf puppet purebasic q qml reasonml rib roboconf routeros rsl ruleslanguage sas scala scheme scilab smali smalltalk sml sqf stan stata step21 stylus subunit taggerscript tap tcl thrift tp twig vala vbscript vbscript-html verilog vhdl vim wren x86asm xl xquery zephir docker build -t example_img \
--add-host=host.docker.internal:host-gateway \
--build-arg http_proxy=http://host.docker.internal:7890 \
--build-arg https_proxy=http://host.docker.internal:7890 \
.
Note: The --build-arg
passed as an argument is not the same as the ENV
in a Dockerfile. Using ENV will embed the configuration into the image, which may not be what you want.
Running Proxy If your process in container requires a proxy, for example, if your Node.js code needs to download a specific resource, you may need to run through a proxy:
auto — arduino bash c cpp csharp css diff go graphql ini java javascript json kotlin less lua makefile markdown objectivec perl php php-template plaintext python python-repl r ruby rust scss shell sql swift typescript vbnet wasm xml yaml 1c abnf accesslog actionscript ada angelscript apache applescript arcade armasm asciidoc aspectj autohotkey autoit avrasm awk axapta basic bnf brainfuck cal capnproto ceylon clean clojure clojure-repl cmake coffeescript coq cos crmsh crystal csp d dart delphi django dns dockerfile dos dsconfig dts dust ebnf elixir elm erb erlang erlang-repl excel fix flix fortran fsharp gams gauss gcode gherkin glsl gml golo gradle groovy haml handlebars haskell haxe hsp http hy inform7 irpf90 isbl jboss-cli julia julia-repl lasso latex ldif leaf lisp livecodeserver livescript llvm lsl mathematica matlab maxima mel mercury mipsasm mizar mojolicious monkey moonscript n1ql nestedtext nginx nim nix node-repl nsis ocaml openscad oxygene parser3 pf pgsql pony powershell processing profile prolog properties protobuf puppet purebasic q qml reasonml rib roboconf routeros rsl ruleslanguage sas scala scheme scilab smali smalltalk sml sqf stan stata step21 stylus subunit taggerscript tap tcl thrift tp twig vala vbscript vbscript-html verilog vhdl vim wren x86asm xl xquery zephir docker run --rm \
--add-host=host.docker.internal:host-gateway \
--env http_proxy=http://host.docker.internal:7890 \
--env https_proxy=http://host.docker.internal:7890 \
-it ubuntu /bin/bash
For you reference, see also Docker's official docs:
That's all for now, thanks for reading, Stay Awsome!