Docker/Boot2Docker: Set HTTP/HTTPS proxies for docker on OS X

后端 未结 6 919
渐次进展
渐次进展 2020-12-07 09:29

In short: How can I set the HTTP/HTTPS proxies for Docker on Mac OS X?

In detail:

I run Docker (1.12) on Mac OS X

相关标签:
6条回答
  • 2020-12-07 09:48

    The config file in boot2docker should be /var/lib/boot2docker/profile, edit this file to custom http(s) proxy.

    0 讨论(0)
  • 2020-12-07 09:50

    If you are using Docker for Mac and are behind a proxy environment.

    Click on the docker icon on top menu bar. (like shown in step 1.3 here )

    Go to Preferences > Advanced and set the proxy in HTTP and HTTPS options there. Click Apply and Restart below it. You are good to go. :)

    0 讨论(0)
  • 2020-12-07 09:52

    The config files you need to modify won't be on your OS X file system, they'll be attached to the Tiny Core Linux VM which acts as your local Docker server.

    To configure the proxy for that, first start Boot2docker from Applications. Once it's started, get a terminal window and ssh into the VM:

    bash-3.2$ boot2docker ssh
    Warning: Permanently added '[localhost]:2022' (RSA) to the list of known hosts.
                            ##        .
                      ## ## ##       ==
                   ## ## ## ##      ===
               /""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
               \______ o          __/
                 \    \        __/
                  \____\______/
     _                 _   ____     _            _
    | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
    | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
    | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
    |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
    boot2docker: 1.0.1
                 master : cad5ece - Fri Jun 20 02:03:40 UTC 2014
    docker@boot2docker:~$
    

    Now create/modify /var/lib/boot2docker/profile to set proxy info:

    docker@boot2docker:~$ sudo vi /var/lib/boot2docker/profile 
    

    Tinycore needs the proxy info as follows: protocol://ip:port
    To be safe I set proxies for both HTTP and HTTPS.

    export HTTP_PROXY=http://your.proxy.name:8080
    export HTTPS_PROXY=http://your.proxy.name:8080
    

    Now you can restart the VM docker service and exit the VM.

    docker@boot2docker:~$ sudo /etc/init.d/docker restart
    docker@boot2docker:~$ exit
    Connection to localhost closed.
    

    You should be able to run the client against the VM instance now.

    bash-3.2$ docker search ubuntu
    NAME                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    ubuntu                                           Official Ubuntu base image                      356                  
    stackbrew/ubuntu                                 Official Ubuntu base image                      39                   
    crashsystems/gitlab-docker                       A trusted, regularly updated build of GitL...
    

    This change is persisted through VM restarts. You should only need to do it once.

    For the record, VirtualBox has a global preference setting for proxies but nothing I tried there would work.

    0 讨论(0)
  • 2020-12-07 09:54

    I solved this problem by setting proxy config in .profile file:

    docker@boot2docker:~$ vi ~/.profile
    

    add your proxy at the end:

    #
    PS1='\u@\h:\w\$ '
    PAGER='less -EM'
    MANPAGER='less -isR'
    
    EDITOR=vi
    
    export PS1 PAGER FILEMGR EDITOR MANPAGER
    
    export BACKUP=1
    [ "`id -un`" = "`cat /etc/sysconfig/tcuser`" ] && echo "$BACKUP" | sudo tee /etc/sysconfig/backup >/dev/null 2>&1
    export FLWM_TITLEBAR_COLOR="58:7D:AA"
    
    if [ -f "$HOME/.ashrc" ]; then
       export ENV="$HOME/.ashrc"
       . "$HOME/.ashrc"
    fi
    
    TERMTYPE=`/usr/bin/tty`
    [ ${TERMTYPE:5:3} == "tty" ] && (
    [ ! -f /etc/sysconfig/Xserver ] ||
    [ -f /etc/sysconfig/text ] ||
    [ -e /tmp/.X11-unix/X0 ] ||
    startx
    )
    
    export HTTP_PROXY=http://proxy.XX.com:8080
    export HTTPS_PROXY=http://proxy.XX.com:8080
    

    finally, restart your Boot2Docker.

    0 讨论(0)
  • 2020-12-07 09:55

    As of the recent (August 2015) 1.8 release, docker's recommended way to create docker hosts - including boot2docker VMs - is through its docker-machine utility.

    And also since version 1.8, docker-machine now supports the configuration of the proxies at VM creation time via an invocation like the following:

    docker-machine create -d virtualbox \
        --engine-env HTTP_PROXY=http://192.37.246.181:2010 \
        --engine-env HTTPS_PROXY=http://192.37.246.181:2010 \
        --engine-env NO_PROXY=novartis.net \
        default
    

    This results in a VM that has the specified environment variables already added to the initialization file /var/lib/boot2docker/profile - no need to manually add them anymore.

    0 讨论(0)
  • 2020-12-07 09:59

    To solve the problem with curl in docker build, I added the following inside the Dockerfile:

    ENV http_proxy=http://infoprx2:8080
    ENV https_proxy=http://infoprx2:8080
    RUN apt-get update && apt-get install -y curl vim
    

    Note that the ENV statement is BEFORE the RUN statement.

    and in order to make the docker daemon able to access the internet (I use kitematic with boot2docker), I added the following into /var/lib/boot2docker/profile :

    export HTTP_PROXY=http://infoprx2:8080
    export HTTPS_PROXY=http://infoprx2:8080
    
    0 讨论(0)
提交回复
热议问题