As you might be already aware, Docker by Docker Inc is a widely used tool for containers. Containerization is an approach to software development in which an application and its versioned set of dependencies plus its environment configuration abstracted as deployment manifest files are packaged altogether (the container image), tested as a unit and finally deployed (the container or image instance) to the host Operating System (OS).
Containers isolate applications from each other on a shared operating system (OS). This approach standardizes application program delivery, allowing apps to run as Linux or Windows containers on top of the host OS (Linux or Windows). Because containers share the same OS kernel (Linux or Windows), they are significantly lighter than virtual machine (VM) images.
In this post, we’ll go through series of steps required to install Docker on Ubuntu Server. You need to be running on 14.04 LTS or 16.04 LTS version for this. We would be installing docker on Ubuntu 16.04 LTS for this post’s purpose.
First thing is to make sure that system binaries are up to date. This can be done by running:
$ sudo apt-get update $ sudo apt-get upgrade
Unless you have a strong reason not to, install the linux-image-extra-* packages, which allow Docker to use the aufs storage drivers.
$ sudo apt-get update $ sudo apt-get install \ linux-image-extra-$(uname -r) \ linux-image-extra-virtual
Next step is to setup Docker’s repositories. This way the upgrade and installation can be made easier and it is more widely used approach. Alternatively, you can use curl to download Debian package and perform installation/upgrades manually. We would be using former method for this post.
First step would be to install packages to allow apt to use a repository over HTTPS (in most cases these should be already installed):
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
Now, we need to add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Next we need to setup repository. We would be setting up stable repository path:
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Now, we need to update the apt index:
sudo apt-get update
After this, we can check which versions of docker are available using below command:
$ apt-cache madison docker-ce
The contents of the list depend upon which repositories are enabled, and will be specific to your version of Ubuntu. We can go with the latest version or choose specific versions of our choice. For now, we would go with latest version (but we’ll still be specifying version while using command):
$ sudo apt-get install docker-ce=17.03.2~ce-0~ubuntu-xenial
When prompted to go ahead, type Y (for yes).
Docker will be installed and docker daemon should be started automatically.
Now we would be testing if docker is working correctly or not. First we can use below command for this purpose:
$ docker --version
We can also try to run a sample image called hello-world to check if docker is running correctly:
sudo docker run hello-world
You should be seeing below output:
You need to use sudo to run further commands. for example, we can use below commands to show running images in docker:
$ sudo docker images
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user.
If you don’t want to use sudo when you use the docker command, create a Unix group called docker(which should be created as part of installation) and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group. In our case, we would be adding current user to docker group using below command (you need to change this to your user):
$ sudo usermod -aG docker mogoyal
Next, we need to logout and login back to get new privileges assigned. After this, we would be able to run docker commands as non-sudo:
Do note that docker group has same privileges as root user. So, all users added to this group will have root user access.