Monday, June 23, 2014

Bootstrap RESTful Docker on Ubuntu

The most "devOps way" of communicating with the Docker server is to expose it via the REST API. And then using the HTTP client of your choice to send commands to that Docker server.  

Here is what you need to do in order to set up the Docker server exposed via REST endpoint on Ubuntu 14.04.

Install Docker

Here is the Official Ubuntu installation documentation in the nutshell - to install Docker on Ubuntu just type the following command into your shell:

curl -s https://get.docker.io/ubuntu/ | sudo sh

Expose Docker via HTTP

By default Docker is exposed only via the Unix sockets. You can change it with the additional -H (host) option.

sudo sh -c 'echo "DOCKER_OPTS=\"-H unix:///var/run/docker.sock -H tcp://127.0.0.1:2375\"" > /etc/default/docker'
sudo service docker restart
In order to verify that Docker has been properly exposed via HTTP, execute the following command:

curl http://127.0.0.1:2375/version
{"ApiVersion":"1.12","Arch":"amd64","GitCommit":"990021a","GoVersion":"go1.2.1","KernelVersion":"3.13.0-29-generic","Os":"linux","Version":"1.0.1"}

Running Docker without root

If you wanna execute docker command without sudo, add yourself to the docker system group:

usermod -a -G docker yourUserName

Fabric8 readiness

The settings presented above are the default Docker setup expected by the Fabric8 Docker integration. If you followed this instruction, you can safely play with the Fabric8 Docker containers.

2 comments:

  1. Hey! The proper way to add a user to a group is either `# usermod -a -G docker rylee` where `rylee` is your username, or `# gpasswd -a rylee docker`, where rylee is the username. Manually editing /etc/group (and /etc/gshadow) is *not* recommended.

    ReplyDelete
  2. Good point! Fixed :) . Many thanks for the comment!

    ReplyDelete