|
| 1 | +--- |
| 2 | +title: Private resources access |
| 3 | +description: Use Docker Build Cloud with private package repositories |
| 4 | +keywords: docker build build, private packages, registry, package repository, vpn, forward-hosts |
| 5 | +--- |
| 6 | + |
| 7 | +> **Experimental** |
| 8 | +> |
| 9 | +> This feature is experimental and subject to change without notice. |
| 10 | +{ .experimental } |
| 11 | + |
| 12 | +If your builds require access to images or other packages hosted on private or |
| 13 | +on-premises artifact repositories, the builder must be able to access these |
| 14 | +resources, or the build will fail. For example, if your organization hosts a |
| 15 | +private [PyPI](https://pypi.org/) repository on a VPN, Docker Build Cloud would |
| 16 | +not be able to access it by default, since it isn't on the same network as your |
| 17 | +VPN. |
| 18 | + |
| 19 | +To enable the cloud builder to access your internal resources, you can |
| 20 | +configure your Buildx client to act as a forward proxy for the builder to |
| 21 | +access your internal resources through a secure tunnel. |
| 22 | + |
| 23 | +## How it works |
| 24 | + |
| 25 | +When you create a cloud builder with the `forward-hosts` option, the builder |
| 26 | +uses the client as a proxy to forward requests to the specified hostnames. |
| 27 | + |
| 28 | +To use this feature, you need: |
| 29 | + |
| 30 | +- Docker Desktop version 4.32.0 or later (Buildx version `0.15.1-desktop.1`) |
| 31 | + |
| 32 | +## Configuration |
| 33 | + |
| 34 | +Connection-forwarding is configured on a per-builder and per-client basis. To |
| 35 | +enable it, set the `forward-hosts` driver option when creating the builder. For |
| 36 | +example, to create a builder that forwards connections to an internal registry |
| 37 | +on `registry.example.com:5000`, run the following command: |
| 38 | + |
| 39 | +```console |
| 40 | +$ docker buildx create \ |
| 41 | + --driver cloud \ |
| 42 | + --driver-opt "forward-hosts=registry.example.com:5000" \ |
| 43 | + <org>/<builder> |
| 44 | +``` |
| 45 | + |
| 46 | +Replace `registry.example.com` with the hostname of your internal registry, and |
| 47 | +`<org>/<builder>` with the namespace of your Docker organization and the name |
| 48 | +of your builder. |
| 49 | + |
| 50 | +After creating the builder with the `forward-hosts` option, you can use it to |
| 51 | +build images with private packages from the hostnames you specified. |
| 52 | + |
| 53 | +### Multiple hostnames |
| 54 | + |
| 55 | +If you need to forward connections to multiple hostnames, specify each hostname |
| 56 | +separated by a semicolon. The following example enables forwarding for |
| 57 | +`pypi.internal` and `npm.internal`: |
| 58 | + |
| 59 | +```console |
| 60 | +$ docker buildx create \ |
| 61 | + --driver cloud \ |
| 62 | + --driver-opt "forward-hosts=pypi.internal;npm.internal" \ |
| 63 | + <org>/<builder> |
| 64 | +``` |
| 65 | + |
| 66 | +You can also use wildcards to forward connections for all hostnames that match |
| 67 | +a specific pattern. The following example forwards all requests to hostnames |
| 68 | +ending with `*.internal`: |
| 69 | + |
| 70 | +```console |
| 71 | +$ docker buildx create \ |
| 72 | + --driver cloud \ |
| 73 | + --driver-opt "forward-hosts=*.internal" \ |
| 74 | + <org>/<builder> |
| 75 | +``` |
| 76 | + |
| 77 | +To forward all hosts, use `*`: |
| 78 | + |
| 79 | +```console |
| 80 | +$ docker buildx create \ |
| 81 | + --driver cloud \ |
| 82 | + --driver-opt "forward-hosts=*" \ |
| 83 | + <org>/<builder> |
| 84 | +``` |
| 85 | + |
| 86 | +## Authentication |
| 87 | + |
| 88 | +If your internal artifacts require authentication, make sure that you |
| 89 | +authenticate with the repository either before or during the build. For |
| 90 | +internal packages like npm or PyPI, use [build secrets](/manuals/build/building/secrets.md) |
| 91 | +to authenticate during the build. For internal OCI registries, use `docker |
| 92 | +login` to authenticate before building. |
| 93 | + |
| 94 | +Note that if you use a private registry that requires authentication, you will |
| 95 | +need to authenticate with `docker login` twice before building. This is because |
| 96 | +the cloud builder needs to authenticate with Docker to use the cloud builder, |
| 97 | +and then again to authenticate with the private registry. |
| 98 | + |
| 99 | +```console |
| 100 | +$ echo $DOCKER_PAT | docker login docker.io -u <username> --password-stdin |
| 101 | +$ echo $REGISTRY_PASSWORD | docker login registry.example.com -u <username> --password-stdin |
| 102 | +$ docker build --builder <cloud-builder> --tag registry.example.com/<image> --push . |
| 103 | +``` |
0 commit comments