Chapter2-Installing Docker on Ubuntu
Requirements
- Be running a 64-bit architecture (currently x86_64 and amd64 only). 32-bit is NOT currently supported.
- Be running a Linux 3.8 or later kernel. Some earlier kernels from 2.6.x and later will run Docker successfully. Your results will greatly vary, though, and if you need support you will often be asked to run on a more recent kernel.
- The kernel must support an appropriate storage driver. For example,
– Device Mapper
– AUFS
– vfs.
– btrfs
– The default storage driver is usually Device Mapper. - cgroups and namespaces kernel features must be supported and enabled.
Checking for prerequisites
1. Checking for Kernel
1 | uname -a |
If, however, we’re using an earlier release of Ubuntu 12.04 Precise, we may have a 3.2 kernel. We can easily upgrade our Ubuntu 12.04 to the later kernel; for example, at the time of writing, the 3.8 kernel was available to install via apt-get
.
2. Checking for Device Mapper
We’re going to make use of the Device Mapper storage driver.Device Mapper should be installed on any Ubuntu 12.04 or later hosts, but we can confirm it is installed like so:1
ls -l /sys/class/misc/device-mapper
We could also check in /proc/devices for a device-mapper entry.1
sudo grep device-mapper /proc/devices
If neither is present, we can also try to load the dm_mod module.1
sudo modprobe dm_mod
Installing docker
First, we add the Docker APT repository. You may be prompted to confirm that you wish to add the repository and have the repositories GPG automatically added to your host.1
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
Adding the Docker repository GPG key1
curl -s https://get.docker.io/gpg | sudo apt-key add -
Now, we update our APT sources.1
sudo apt-get update
We can now install the Docker package itself.1
sudo apt-get install lxc-docker
Docker installation script
There is also an alternative method available to install Docker on an appropriate host using a remote installation script.1
curl https://get.docker.io/ | sudo sh
The Docker daemon
After we’ve installed Docker, we need to confirm that the Docker daemon is run- ning. Docker runs as a root-privileged daemon process to allow it to handle op- erations that can’t be executed by normal users (e.g., mounting filesystems). The docker binary runs as a client of this daemon and also requires root privileges to run.
The Docker daemon should be started by default when the Docker package is installed. By default, the daemon listens on a Unix socket at /var/run/docker.↩ sock for incoming Docker requests. If a group named docker exists on our system, Docker will apply ownership of the socket to that group. Hence, any user that belongs to the docker group can run Docker without needing to use the sudo command.1
sudo gpasswd -a <your_login> docker
Now, you can execute docker without root authority.
Checking that the Docker daemon is running
1 | ## Checking the status of the Docker daemon |