Monthly Archives: January 2016

Docker: connect to network socket

Introduction

By default, the docker daemon listens on a unix socket, a unix domain socket (or IPC socket) is created at /var/run/docker.sock, requiring either root permission, or docker group membership. If you want to have docker listen on a TCP socket, you could do this as well.

You could do this as follows (note that 192.168.100.2 is the IP address of my host running docker):

root@ubuntu1:/home/cloud-user# docker -H 192.168.100.2:2375 -d &
[1] 3909
root@ubuntu1:/home/cloud-user# Warning: '-d' is deprecated, it will be removed soon. See usage.
WARN[0000] please use 'docker daemon' instead.
WARN[0000] /!\ DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING /!\
INFO[0000] API listen on 192.168.100.2:2375
INFO[0000] [graphdriver] using prior storage driver "aufs"
INFO[0000] Firewalld running: false
INFO[0000] Default bridge (docker0) is assigned with an IP address 172.17.42.1/16. Daemon option --bip can be used to set a preferred IP address
WARN[0000] Your kernel does not support swap memory limit.
INFO[0000] Loading containers: start.
..
INFO[0000] Loading containers: done.
INFO[0000] Daemon has completed initialization
INFO[0000] Docker daemon                                 commit=a34a1d5 execdriver=native-0.2 graphdriver=aufs version=1.9.1

When running netstat, you can see that docker is listening on TCP socket 192.168.100.2:2375:

root@ubuntu1:/home/cloud-user# netstat -tlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:ssh                   *:*                     LISTEN      1145/sshd
tcp        0      0 localhost:52698         *:*                     LISTEN      3744/0
tcp        0      0 host-192-168-100-2:2375 *:*                     LISTEN      3909/docker
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1145/sshd
tcp6       0      0 ip6-localhost:52698     [::]:*                  LISTEN      3744/0
root@ubuntu1:/home/cloud-user#

We then could boot a different (Ubuntu in my case) host, with an older version of Docker. You can see that this host is running version 1.6.2 whereas the other host above (192.168.100.2) was running version 1.9.1/

cloud-user@ubuntu-demo:~$ docker -v
Docker version 1.6.2, build 7c8fca2

On the host running the older docker version, we can then set an environment variable called DOCKER_HOST:

root@ubuntu-demo:/home/cloud-user# export DOCKER_HOST="tcp://192.168.100.2:2375"

If we then check the docker version, you will see that the client docker version is 1.6.2 (of the host we just installed), but the docker daemon connects to the server with version 1.9.1, which is the host on 192.168.100.2.

root@ubuntu-demo:/home/cloud-user# docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.2.1
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64
Server version: 1.9.1
Server API version: 1.21
Go version (server): go1.4.3
Git commit (server): a34a1d5
OS/Arch (server): linux/amd64

Docker: install and upgrade (Ubuntu host)

Introduction

This is the first post (of probably many more in the near future) to experiment with Docker. Goal is to build step by step a general understanding of container technology. As usual, I won’t elaborate on what containers are and what Docker is as there are many sites available that would probably do a better job on explaining these concepts than I can (e.g check out the documentation on Docker here).

Installing Docker

In this tutorial, we will be working on an Ubuntu 14.04 host (running on Openstack for what it matters). Installation is quite simple. Just run:

cloud-user@ubuntu-demo:~$ sudo su
root@ubuntu-demo:/home/cloud-user# apt-get install -y docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  btrfs-tools debootstrap lxc rinse
Recommended packages:
  aufs-tools cgroupfs-mount cgroup-lite git
The following NEW packages will be installed:
  docker.io
0 upgraded, 1 newly installed, 0 to remove and 99 not upgraded.
Need to get 4749 kB of archives.
After this operation, 29.1 MB of additional disk space will be used.
Get:1 http://aer01-1-csx.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/universe docker.io amd64 1.6.2~dfsg1-1ubuntu4~14.04.1 [4749 kB]
Fetched 4749 kB in 0s (30.8 MB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package docker.io.
(Reading database ... 34746 files and directories currently installed.)
Preparing to unpack .../docker.io_1.6.2~dfsg1-1ubuntu4~14.04.1_amd64.deb ...
Unpacking docker.io (1.6.2~dfsg1-1ubuntu4~14.04.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up docker.io (1.6.2~dfsg1-1ubuntu4~14.04.1) ...
Adding group `docker' (GID 112) ...
Done.
docker start/running, process 2028
Processing triggers for ureadahead (0.100.0-16) ...
root@ubuntu-demo:/home/cloud-user# docker

Once installation is finished, you can check the docker version you just installed

root@ubuntu-demo:/home/cloud-user# docker --version
Docker version 1.6.2, build 7c8fca2

Version 1.6.2 is pretty old as a quick check on Docker’s release notes, learns us we’ve already reached version 1.10.3. So let’s go ahead and upgrade docker to a later version.

cloud-user@ubuntu-demo:~$ docker -v
Docker version 1.6.2, build 7c8fca2

cloud-user@ubuntu-demo:~$ sudo su
root@ubuntu-demo:/home/cloud-user# wget -qO- https://get.docker.com/gpg | apt-key add -
OK
root@ubuntu-demo:/home/cloud-user# echo deb http://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list
root@ubuntu-demo:/home/cloud-user# apt-get update
Ign http://aer01-1-csx.clouds.archive.ubuntu.com trusty InRelease
<... output of apt-get command...>
Fetched 2604 kB in 2s (883 kB/s)
Reading package lists... Done
root@ubuntu-demo:/home/cloud-user#

We can then go ahead and install docker using the following command

root@ubuntu-demo:/home/cloud-user# sudo apt-get install lxc-docker
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  lxc-docker-1.9.1
Recommended packages:
  aufs-tools git cgroupfs-mount cgroup-lite
The following packages will be REMOVED:
  docker.io
The following NEW packages will be installed:
  lxc-docker lxc-docker-1.9.1
0 upgraded, 2 newly installed, 1 to remove and 99 not upgraded.
Need to get 8497 kB of archives.
After this operation, 1272 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://get.docker.com/ubuntu/ docker/main lxc-docker-1.9.1 amd64 1.9.1 [8495 kB]
Get:2 http://get.docker.com/ubuntu/ docker/main lxc-docker amd64 1.9.1 [2094 B]
Fetched 8497 kB in 5s (1650 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
(Reading database ... 34843 files and directories currently installed.)
Removing docker.io (1.6.2~dfsg1-1ubuntu4~14.04.1) ...
docker stop/waiting
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Selecting previously unselected package lxc-docker-1.9.1.
(Reading database ... 34750 files and directories currently installed.)
Preparing to unpack .../lxc-docker-1.9.1_1.9.1_amd64.deb ...
Unpacking lxc-docker-1.9.1 (1.9.1) ...
Selecting previously unselected package lxc-docker.
Preparing to unpack .../lxc-docker_1.9.1_amd64.deb ...
Unpacking lxc-docker (1.9.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up lxc-docker-1.9.1 (1.9.1) ...
Installing new version of config file /etc/init.d/docker ...
Installing new version of config file /etc/init/docker.conf ...
docker start/running, process 2523
Processing triggers for ureadahead (0.100.0-16) ...
Setting up lxc-docker (1.9.1) ...
root@ubuntu-demo:/home/cloud-user# docker -v
Docker version 1.9.1, build a34a1d5
root@ubuntu-demo:/home/cloud-user#

If all went well, you should now have a newer version of docker running. In any case, you can check it as follows:

root@ubuntu-demo:/home/cloud-user# docker -v
Docker version 1.9.1, build a34a1d5