Skip to content

Instantly share code, notes, and snippets.

@justagist
Last active January 16, 2023 22:11
Show Gist options
  • Save justagist/7b544626136537774961c5c5f563d18d to your computer and use it in GitHub Desktop.
Save justagist/7b544626136537774961c5c5f563d18d to your computer and use it in GitHub Desktop.
Proxy Setup - Ubuntu 18.04 (apt, docker, curl)

Environment proxy variables:

Replace your proxy hostname and port number instead of webcache.cs.bham.ac.uk:3128 below.

Set the following in your .bashrc file:

export HTTP_PROXY=http://webcache.cs.bham.ac.uk:3128
export HTTPS_PROXY=http://webcache.cs.bham.ac.uk:3128
export FTP_PROXY=http://webcache.cs.bham.ac.uk:3128

export http_proxy=http://webcache.cs.bham.ac.uk:3128
export https_proxy=http://webcache.cs.bham.ac.uk:3128
export ftp_proxy=http://webcache.cs.bham.ac.uk:3128

APT proxy config

Add following lines to /etc/apt/apt.conf:

Acquire::http::Proxy "http://webcache.cs.bham.ac.uk:3128";
Acquire::https::Proxy "http://webcache.cs.bham.ac.uk:3128";
Acquire::ftp::Proxy "http://webcache.cs.bham.ac.uk:3128";

NOTE: For apt-add-repository you might need to add the -E flag after sudo in the command.

Snap proxy settings

Run the following commands:

sudo snap set system proxy.http="http://webcache.cs.bham.ac.uk:3128"
sudo snap set system proxy.https="http://webcache.cs.bham.ac.uk:3128"

Keyserver get key:

Instead of apt-key adv command, use curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x<GPG_KEY>' | apt-key add -

Docker

Docker service:

This has to be done if you want to use docker services behind proxy:

  1. Create the following folder
sudo mkdir -p /etc/systemd/system/docker.service.d
  1. Open new file:
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf
  1. Add the following lines to the file
[Service]
Environment="HTTP_PROXY=http://webcache.cs.bham.ac.uk:3128/"
Environment="HTTP_PROXY=http://webcache.cs.bham.ac.uk:3128/"
Environment="HTTP_PROXY=http://webcache.cs.bham.ac.uk:3128/"

Docker Image Build

If you want to build docker images which require internet, do the following:

  1. Create the following folder (if it doesn't exist):
mkdir ~/.docker/
  1. Open file:
nano ~/.docker/config.json
  1. Add the following lines to it:
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://webcache.cs.bham.ac.uk:3128",
     "httpsProxy": "http://webcache.cs.bham.ac.uk:3128",
     "ftpProxy": "http://webcache.cs.bham.ac.uk:3128"
   }
 }
}
  1. Restart docker service:
sudo systemctl daemon-reload
sudo systemctl restart docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment