Skip to content

Commit de5c9bc

Browse files
authored
Merge pull request cds-hooks#417 from AidanDelaney/fix200/add-proxy-information
Document how pack interacts with http proxies
2 parents ad97a2e + 8f0d6c9 commit de5c9bc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
+++
2+
title="Using Buildpacks with a Proxy"
3+
weight=8
4+
summary="Learn how to use buildpacks behind a HTTP proxy."
5+
+++
6+
7+
Many university or corporate environments use a proxy to access HTTP and HTTPS resources on the web. Proxies introduce two constraints on buildpack built applications:
8+
9+
1. `pack` needs to download buildpacks through the proxies, and
10+
2. applications running in containers created by `pack` need to call APIs behind the proxy.
11+
12+
We show how to solve both of these constraints.
13+
14+
## Making `pack` Proxy Aware
15+
16+
You may need the `pack` command-line tool to download buildpacks and images via your proxy. Building an application with an incorrectly configured proxy results in errors such as the following:
17+
18+
```console
19+
$ pack build sample-app --path samples/apps/java-maven --builder cnbs/sample-builder:bionic
20+
ERROR: failed to build: failed to fetch builder image 'index.docker.io/cnbs/sample-builder:bionic'
21+
: Error response from daemon: Get "https//registry-1.docker.io/v2/": context deadline exceeded
22+
```
23+
24+
The `pack` tool uses the Docker daemon to manage the local image registry on your machine. The `pack` tool will ask the Docker daemon to download buildpacks and images for you. Because of this relationship, between `pack` and the Docker daemon, we need to configure the Docker daemon to use a HTTP proxy. The approach to setting the HTTP proxy depends on your platform:
25+
26+
27+
### Docker Desktop (Windows and MacOS)
28+
Docker's documetation states "Docker Desktop lets you configure HTTP/HTTPS Proxy Settings and automatically propagates these to Docker". Set the system proxy using the [MacOS documentation](https://support.apple.com/en-gb/guide/mac-help/mchlp2591/mac) or [Windows documentation](https://www.dummies.com/computers/operating-systems/windows-10/how-to-set-up-a-proxy-in-windows-10/). The system proxy settings will be used by Docker Desktop.
29+
30+
### Linux
31+
The Docker project documents [how to configure configure the HTTP/HTTPS proxy](https://docs.docker.com/config/daemon/systemd/#httphttps-proxy) settings for the Docker daemon on Linux. You should configure the `HTTP_PROXY` and `HTTPS_PROXY` environment variables as part of the Docker daemon startup.
32+
33+
## Proxy Settings for Buildpacks
34+
35+
Buildpacks may also need to be aware of your http and https proxies at build time. For example python, java and nodejs buildpacks need to be aware of proxies in order to resolve dependencies. To make buildpacks aware of proxies, export the `http_proxy` and `https_proxy` environment variables before invoking `pack`. For example:
36+
37+
```console
38+
export http_proxy=http://user:[email protected]:3128
39+
export https_proxy=https://my-proxy.example.com:3129
40+
pack build sample-app --path samples/apps/java-maven --builder cnbs/sample-builder:bionic
41+
```
42+
43+
## Making your Application Proxy Aware
44+
45+
Your application may need to use http or https proxies to access web-based APIs. In order to make proxy settings available inside containers you should edit your `~/.docker/config.json` file (`%USERPROFILE%\.docker\config.json` on Windows) to contain the proxy information. The `httpProxy`, `httpsProxy` and `noProxy` properties of this configuration file are injected into containers at build time and at run time as the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables respectively. Both the http and https proxy settings are also injected in their lower-case form as `http_proxy` and `https_proxy`.
46+
47+
```json
48+
{
49+
"proxies": {
50+
"default": {
51+
"httpProxy": "http://user:[email protected]:3128",
52+
"httpsProxy": "https://my-proxy.example.com:3129",
53+
"noProxy": "internal.mycorp.example.com"
54+
}
55+
}
56+
}
57+
```
58+
59+
If your application requires a http or https proxy, then you should prefer to read proxy information from the lower-case `http_proxy` and `https_proxy` variables.

0 commit comments

Comments
 (0)