Skip to content

Instantly share code, notes, and snippets.

@justahero
Forked from ampedandwired/Vagrantfile
Last active March 5, 2018 16:39
Show Gist options
  • Save justahero/16064133a5c3b4bbf06050fe02174f76 to your computer and use it in GitHub Desktop.
Save justahero/16064133a5c3b4bbf06050fe02174f76 to your computer and use it in GitHub Desktop.
Configure VM / docker with company proxy CNTLM

Docker

NOTE this is still in progress, currently these steps are not sufficient!

This is a description of how to set up Docker for Mac with the company proxy CNTLM to ensure Internet access is supported.

  • first run ifconfig in the terminal, determine IP of en0 network adapter, e.g. inet 172.23.123.234.

Docker For Mac

  • open Docker for Mac preferences (accessible from menu bar)
  • select Proxies tab, select Manual Proxy Configuration and fill in the IP for both fields Web Server (HTTP) and Secure Web Server (HTTPS)
  • Press Apply & Restart to restart Docker deamon.

CNTLM

This assumes CNTLM is running on 127.0.0.1:3128.

  • edit the CNTLM configuration, e.g. cntlm.conf
  • set entry Gateyway yes
  • set entry Listen 0.0.0.0:3128
# put the following content into ~/.vagrant/Vagrantfile
# install plugin vagrant-proxyconf: vagrant plugin install vagrant-proxyconf
VAGRANTFILE_API_VERSION = "2"
def get_proxy_url
# Doesn't support different proxies for different protocols at present
host_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ENV['https_proxy'] || ENV["HTTPS_PROXY"]
if host_proxy
uri = URI(host_proxy)
if ['localhost', '127.0.0.1'].include? uri.host
# 10.0.2.2 is the default vagrant gateway and should connect to the host OS.
# Confirm this by running 'netstat -r' in the guest.
host_proxy = host_proxy.sub(uri.host, '10.0.2.2')
end
end
host_proxy
end
def configure_proxy(config)
proxy_server = get_proxy_url
if Vagrant.has_plugin?("vagrant-proxyconf") && proxy_server
config.proxy.http = proxy_server
config.proxy.https = proxy_server
config.proxy.no_proxy = "localhost,127.0.0.1"
else
puts "Please install vagrant-proxyconf for internet access via local proxy"
end
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
configure_proxy(config)
config.ssh.forward_agent = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment