Tuesday, February 17, 2015

Docker Up and Running



Finally let us install and play with Docker which is the reason I embarked on the journey.

curl https://get.docker.io/ | sudo sh

This will install the latest docker. 

In my case, it failed at the last step:

+ sh -c docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
FATA[0000] Error response from daemon: 404 page not found

This means docker has been successfully installed, but connecting to docker daemon has failed. This error happens with the latest version 1.17, 1.16 doesn’t have the issue. 

It turns out this error is thanks to the proxy setup. Thanks to the China GFW (Great Firewall), I have to use proxy, but the proxy setup has tripped me up: docker client has to go through proxies to communicate with the docker daemon. To solve this, change the Vagrant file:


config.proxy.no_proxy  = "ubuntu14.04.1,localhost,127.0.0.0/8,127.0.1.1,127.0.1.1*,local.home,127.0.0.1,192.168.33.*,/var/run/docker.sock"

vagrant reload and vagrant ssh into Ubuntu, sudo docker version returns correctly:
vagrant@vagrant-ubuntu-trusty:~$ sudo docker version

Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef

Now check out /etc/default/docker, proxies have been setup:

export HTTP_PROXY=https://<user>:<password>@<proxy-host>:<proxy-port>
 
export NO_PROXY=ubuntu14.04.1,localhost,127.0.0.0/8,127.0.1.1,127.0.1.1*,local.home,127.0.0.1,192.168.33.*,/var/run/docker.sock
 
export http_proxy=https://<user>:<password>@<proxy-host>:<proxy-port>
export 
 
no_proxy=ubuntu14.04.1,localhost,127.0.0.0/8,127.0.1.1,127.0.1.1*,local.home,127.0.0.1,192.168.33.*,/var/run/docker.sock
 

This is not the end of proxy story. Inside a Docker image, I need to setup proxies as well, otherwise,   commands that fetch things from the internet might fail. To setup proxies inside a Docker image, use ENV

Here is a simple Docker file that installs java:

FROM ubuntu:14.04
MAINTAINER apple
ENV REFRESHED_AT 2015-02-02

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

ENV HTTPS_PROXY https://<user>:<password>@<proxy-host>:<proxy-port>
ENV https_proxy https://<user>:<password>@<proxy-host>:<proxy-port>
ENV HTTP_PROXY https://<user>:<password>@<proxy-host>:<proxy-port>
ENV http_proxy https://<user>:<password>@<proxy-host>:<proxy-port>
 
RUN  apt-get update &&  apt-get install -y curl openjdk-7-jre-headless unzip wget


No comments:

Post a Comment