22

I'm trying to get a working Docker installation following this tutorial: http://docs.docker.io/en/latest/installation/windows/

So far, I got the VM running with a manually downloaded repository (followed the GitHub link and downloaded as a ZIP file, because "git clone" didn't work behind my corporate proxy, even after setting up the proxy with "git conf --global http.proxy ..." - it kept asking me for authentification 407, although I entered my user name and password).

Now I am in the state in which I should use "docker run busybox echo hello world" (Section "Running Docker").

When I do this, I first get told that Docker is not installed (as shown at the bottom of the tutorial), and then, after I got it with apt-get install docker, I get "Segmentation Fault or critical error encountered. Dumping core and aborting."

What can I do now? Is this because I didn't use git clone or is something wrong with the Docker installation? I read somewhere, that apt-get install docker doesn't install the Docker I want, but some GNOME tool. Can I maybe specify my apt-request to get the right tool?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3032785
  • 221
  • 1
  • 2
  • 3
  • After running `vagrant up`, run `vagrant provision`. Let me know if there are any errors. The vagrantfile/virtualbox requires internet connectivity as well. – Kyle Kelley Nov 25 '13 at 16:14
  • I have now chosen the other way round - after setting the VM up with Vagrant, I started it in its own shell with VirtualBox and followed the Linux/Ubuntu-Tutorial on how to install lxc-docker, which finally worked fine after plenty of proxy-configurations. Atm, I'm only stuck again at the point, where I should use "docker run busybox" (or any other repository). Although docker is installed, the connection times out while pulling the desired repository, which is a proxy-issue again, I guess. – user3032785 Dec 03 '13 at 14:40
  • If you wanted to use Git behind an authenticated proxy, you could setup a Squid with a `cache_peer` to your proxy and use it as your `http.proxy`. – kb1000 Mar 30 '18 at 04:37

1 Answers1

33

Windows Boot2Docker behind corporate proxy

(Context: March 2015, Windows 7, behind corporate proxy)

TLDR; see GitHub project VonC/b2d:

Clone it and:

  • configure ..\env.bat following the env.bat.template,
  • add the alias you want in the 'profile' file,
  • execute senv.bat then b2d.bat.

You then are in a properly customized boot2docker environment with:

  • an ssh session able to access internet behind corporate proxy when you type docker search/pull.
  • Dockerfiles able to access internet behind corporate proxy when they do an apt-get update/install and you type a docker build.

Installation and first steps

If you are admin of your workstation, you can run boot2docker install on your Windows.
It currently comes with:

  • Boot2Docker 1.5.0 (Docker v1.5.0, Linux v3.18.5)
  • Boot2Docker Management Tool v1.5.0
  • VirtualBox v4.3.20-r96997
  • msysGit v1.9.5-preview20141217

Then, once installed:

  • add c:\path\to\Boot2Docker For Windows\ in your %PATH%
  • (one time): boot2docker init
  • boot2docker start
  • boot2docker ssh
  • type exit to exit the ssh session, and boot2docker ssh to go back in: the history of commands you just typed is preserved.
  • if you want to close the VM, boot2docker stop

You actually can see the VM start or stop if you open the Virtual Box GUI, and type in a DOS cmd session boot2docker start or stop.


Hosts & Proxy: Windows => Boot2Docker => Docker Containers

The main point to understand is that you will need to manage 2 HOSTS:

  • your Windows workstation is the host to the Linux Tiny Core run by VirtualBox in order for you to define and run containers
    (%HOME%\.boot2docker\boot2docker.iso =>
    .%USERPROFILE%\VirtualBox VMs\boot2docker-vm\boot2docker-vm.vmdk),
  • Your boot2docker Linux Tiny Core is host to your containers that you will run.

In term of proxy, that means:

  • Your Windows Host must have set its HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variable (you probably have them already, and they can be used for instance by the Virtual Box to detect new versions of Virtual Box)
  • Your Tiny Core Host must have set http_proxy, https_proxy and no_proxy (note the case, lowercase in the Linux environment) for:
    • the docker service to be able to query/load images (for example: docker search nginx).
      If not set, the next docker pull will get you a dial tcp: lookup index.docker.io: no such host.
      This is set in a new file /var/lib/boot2docker/profile: it is profile, not .profile.
    • the docker account (to be set in /home/docker/.ashrc), if you need to execute any other command (other than docker) which would require internet access)
    • any Dockerfile that you would create (or the next RUN apt-get update will get you a, for example, Could not resolve 'http.debian.net').
      That means you must add the lines ENV http_proxy http://... first, before any RUN command requiring internet access.

A good no_proxy to set is:

.company,.sock,localhost,127.0.0.1,::1,192.168.59.103

(with '.company' the domain name of your company, for the internal sites)


Data persistence? Use folder sharing

The other point to understand is that boot2docker uses Tiny Core, a... tiny Linux distribution (the .iso file is only 26 MB).
And Tiny Core offers no persistence (except for a few technical folders): if you modify your ~/.ashrc with all your preferred settings and alias... the next boot2docker stop / boot2docker start will restore a pristine Linux environment, with your modification gone.

You need to make sure the VirtualBox has the Oracle_VM_VirtualBox_Extension_Pack downloaded and added in the Virtual Box / File / Settings / Extension / add the Oracle_VM_VirtualBox_Extension_Pack-4.x.yy-zzzzz.vbox-extpack file).

As documented in boot2docker, you will have access (from your Tiny Core ssh session) to /c/Users/<yourLogin> (ie the %USERPROFILE% is shared by Virtual Box)


Port redirection? For container and for VirtualBox VM

The final point to understand is that no port is exported by default:

  • your container ports are not visible from your Tiny Core host (you must use -p 80:80 for example in order to expose the 80 port of the container to the 80 port of the Linux session)
  • your Tiny Cort ports are not exported from your Virtual Box VM by default: even if your container is visible from within Tiny Core, your Windows browser won't see it: http://127.0.0.1 won't work "The connection was reset".

For the first point, docker run -it --rm --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 won't work without a -p 80:80 in it.

For the second point, define an alias doskey vbm="c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" $*, and then: - if the Virtual Box 'boot2docker-vm' is not yet started, uses vbm modifyvm - if the Virtual Box 'boot2docker-vm' is already started, uses vbm controlvm

Typically, if I realize, during a boot2docker session, that the port 80 is not accessible from Windows:

vbm controlvm "boot2docker-vm" natpf1 "tcp-port80,tcp,,80,,80";
vbm controlvm "boot2docker-vm" natpf1 "udp-port80,udp,,80,,80";

Then, and only then, I can access http://127.0.0.1


Persistent settings: copied to docker service and docker account

In order to use boot2docker easily:

  • create on Windows a folder %USERPROFILE%\prog\b2d
  • add a .profile in it (directly in Windows, in%USERPROFILE%\prog\b2d), with your settings and alias.

For example (I modified the original /home/docker/.ashrc):

# ~/.ashrc: Executed by SHells.
#
. /etc/init.d/tc-functions
if [ -n "$DISPLAY" ]
then
        `which editor >/dev/null` && EDITOR=editor || EDITOR=vi
else
        EDITOR=vi
fi
export EDITOR

# Alias definitions.
#
alias df='df -h'
alias du='du -h'

alias ls='ls -p'
alias ll='ls -l'
alias la='ls -la'

alias d='dmenu_run &'
alias ce='cd /etc/sysconfig/tcedir'

export HTTP_PROXY=http://<user>:<pwd>@proxy.company:80
export HTTPS_PROXY=http://<user>:<pwd>@proxy.company:80
export NO_PROXY=.company,.sock,localhost,127.0.0.1,::1,192.168.59.103

export http_proxy=http://<user>:<password>@proxy.company:80
export https_proxy=http://<user>:<password>@proxy.company:80
export no_proxy=.company,.sock,localhost,127.0.0.1,::1,192.168.59.103

alias l='ls -alrt'
alias h=history
alias cdd='cd /c/Users/<user>/prog/b2d'

ln -fs /c/Users/<user>/prog/b2d /home/docker

(192.168.59.103 is usually the ip returned by boot2docker ip)


Putting everything together to start a boot2docker session: b2d.bat

  • create and add a b2d.bat script in your %PATH% which will:
    • start boot2docker
    • copy the right profile, both for the docker service (which is restarted) and for the /home/docker user account.
    • initiate an interactive ssh session

That is:

doskey vbm="c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" $*
boot2docker start
boot2docker ssh sudo cp -f /c/Users/<user>/prog/b2d/.profile /var/lib/boot2docker/profile
boot2docker ssh sudo /etc/init.d/docker restart
boot2docker ssh cp -f /c/Users/<user>/prog/b2d/.profile .ashrc
boot2docker ssh

In order to enter a new boot2docker session, with your settings defined exactly as you want, simply type:

b2d

And you are good to go:


End result:

  • a docker search xxx will work (it will access internet)
  • any docker build will work (it will access internet if the ENV http_proxy directives are there)
  • any Windows file from %USERPROFILE%\prog\b2d can be modified right from ~/b2d.
    Or you actually can write and modify those same files (like some Dockerfile) right from your Windows session, using your favorite editor (instead of vi)

And all this, behind a corporate firewall.


Bonus: http only

Tuan adds in the comments:

Maybe my company's proxy doesn't allow https. Here's my workaround:

  • boot2docker ssh,
    kill the docker process and
  • set the proxy export http_proxy=http://proxy.com, then
  • start docker with docker -d --insercure-registry docker.io
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @nwinkler Thank you. I finally have my "docker environment" set exactly as I want it to be, and I am starting to define my different images I need. This is quite an achievement in a *corporate* environment. – VonC Mar 27 '15 at 15:31
  • I know - working in a corporate environment as well :-) – nwinkler Mar 27 '15 at 15:32
  • @VonC I cloned yours but still get this: Error response from daemon: Get https://index.docker.io/v1/search?q=bind: dial tcp 52.5.160.228:443: i/o timeout – Tuan Jun 30 '15 at 09:24
  • @Tuan That would depend on your `env.bat` parameters. What version of docker are you using? – VonC Jun 30 '15 at 09:31
  • @VonC I use the latest 1.7.0. I can use wget or curl to get the ```https://index.docker.io``` contents but not docker. – Tuan Jul 01 '15 at 02:41
  • @Tuan do yu have a proxy set n the env.bat? – VonC Jul 01 '15 at 05:41
  • Yes, @VonC. I'm still research it. – Tuan Jul 01 '15 at 07:28
  • Maybe my company's proxy doesn't allow https. Here's my workaround: ```boot2docker ssh```, kill the docker process and set the proxy ```export http_proxy=http://proxy.com```, then start docker with ```docker -d --insercure-registry docker.io``` – Tuan Jul 04 '15 at 13:22
  • @Tuan Good tip, thank you. I have included it in the answer for more visibility. – VonC Jul 04 '15 at 13:36
  • Can the persistance settings be used with docker-machine as well? Currently, boot2docker is not being released with the docker-toolbox. – Vivek May 25 '16 at 12:57
  • @Vivek Sure: docker-machine does load a boot2docker VM, and when you do a docker-machine ssh, you are in a boot2docker VM. – VonC May 25 '16 at 12:58
  • Ok thanks. I am planning to add an init script to see if it can copy the configuration files from my %USERPROFILE% automatically without having to run batch files. Hope that this folder would be available at the time when init scripts are run. Also what is the persistance of the TinyOS? I can see that my changes survive VM restart, but not host(windows) restart. – Vivek May 25 '16 at 13:02
  • @Vivek "copy the configuration files": That is what I do with `dmssh.bat`: https://github.com/VonC/b2d/blob/bf94e41e909cc6d2e93b9f51991d997ad1448e38/bin/dmssh.bat. Anything copied/modified in /var/lib/boot2docker is persisted by the TinyCore OS. For instance, setting the IP is done with `dmvbf.bat`: https://github.com/VonC/b2d/blob/bf94e41e909cc6d2e93b9f51991d997ad1448e38/bin/dmvbf.bat. That last script is executed only once. The first script is executed each time one wants to open a new ssh session to the docker-machine. – VonC May 25 '16 at 13:07
  • @VonC, Sorry. I am a bit confused. I added proxy settings yesterday and shutdown windows, Today I found them missing from /var/lib/boot2docker/profile. If I restart VM alone I see that the data persists. Is this expected? – Vivek May 25 '16 at 13:16
  • @Vivek Yes: any modification to *existing* file is not persisted. Any *new* file is persisted only if that new file is in `/var/lib/boot2docker`. To persist a modification, you create `/var/lib/boot2docker/bootsync.sh`, which is a file executed by TinyCore (if it exists). In that file, you script the modification you want to see at each new start of the docker-machine. Creating `bootsync.sh` is what I do in line 19: https://github.com/VonC/b2d/blob/bf94e41e909cc6d2e93b9f51991d997ad1448e38/bin/dmvbf.bat#L19 – VonC May 25 '16 at 13:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112922/discussion-between-vivek-and-vonc). – Vivek May 25 '16 at 13:20
  • @Vivek Sorry. No chat at work. I add other commands to bootsync.sh in https://github.com/VonC/b2d/blob/46a600fa7d80a4021860128a4c06fcf5b6a2d138/nodes/blessed/build#L11-L14. Specifically, a script getting and installing a ssl certificate: https://github.com/VonC/b2d/blob/46a600fa7d80a4021860128a4c06fcf5b6a2d138/scripts/add_reg_crt.sh. I dump the content of that script in `bootsync.sh` in order to execute it at each start of the docker-machine. – VonC May 25 '16 at 13:22
  • Hi @VonC I wrote a /var/lib/boot2docker/bootsync.sh with export statements to put the proxies into /var/lib/boot2docker/profile. But after bootup I still see the original profile, in spite of the script having run. And the script works fine when manually run. This means probably there some script that runs after bootsync.sh that recreats the profile file. Do you know where it is, so that I can add my changes after that? – Vivek May 27 '16 at 05:00
  • @Vivek You are right, bootsync.sh would not work for the profile file. The way to add proxy is at docker-machine *creation* with the `--engine-env` option: see `dmcv.bat`: https://github.com/VonC/b2d/blob/bf94e41e909cc6d2e93b9f51991d997ad1448e38/bin/dmcv.bat#L12-L34. The resulting docker-machine will have proxy in its `/var/lib/boot2docker/profile` file. Permanently. – VonC May 27 '16 at 06:02
  • @VonC, thanks for that tip. I was wondering on the same lines i.e profile is set at creation and never changed unless forced. But these steps would mean deletion and recreation of the default machine. Would images be preserved across machine deletions? – Vivek May 27 '16 at 07:27
  • @Vivek No: you need to docker save those images (*not* docker export: http://stackoverflow.com/a/36932570/6309), and restore them with docker load in the new docker-machine. – VonC May 27 '16 at 07:32