Docker is an open-source software that helps to deploy, run applications in a container. The containers are like a virtual machine but consumes fewer resource, easy to manage and will always run the same regardless of operating environment it is running in.
Docker uses cgroups and namespace to allow the independent containers to run within a single Linux instance.
Article will continue after the ad
Note: Docker requires 64-bit operating system, and kernel version must be 3.10 or later.
$ uname -r 4.4.0-31-generic
Setup Docker Repository:
Install below packages to ensure the “apt” work with https method, and that CA certificates are installed.
$ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificates
Add the GPG key for Docker repository on your system.
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Now, add the official Docker repository by running the following command in the terminal.
$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee -a /etc/apt/sources.list.d/docker.list
Update the apt database.
$ sudo apt-get update
Make sure you are installing the docker from the official repository, not from the default Ubuntu 16.04 repo.
$ sudo apt-cache policy docker-engine
You should see the output like below, should have Docker repository details.
docker-engine: Installed: (none) Candidate: 1.12.0-0~xenial Version table: 1.12.0-0~xenial 500 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages 1.11.2-0~xenial 500 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages 1.11.1-0~xenial 500 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages 1.11.0-0~xenial 500 500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
To make a use of aufs storage driver, make sure your system has the linux–image-extra package.
$ sudo apt-get install linux-image-extra-$(uname -r)
Now, install the Docker using the following command.
$ sudo apt-get install docker-engine
Now you have Docker installed on your machine, start the Docker service in case if it is not started automatically after the installation
$ sudo systemctl start docker $ sudo systemctl enable docker.service
Run a docker container to verify the Docker installation
$ sudo docker run hello-world
You should see output like below; this confirms us that Docker is correctly installed.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c04b14da8d14: Pull complete Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
Allow Non-root user to run Docker:
By default, you would require root privilege to run docker commands. To avoid this, I had been using sudo with docker commands. If you want to allow non-root users to run Docker containers, follow the below steps to give them privileges to run a Docker.
Create a group called docker.
$ sudo groupadd docker
Add your user to docker group, replace “raj” with your user name.
$ sudo useradd raj
Add a user to docker group.
$ sudo usermod -aG docker raj
Log out and log back in.
Now, you should now be able to run docker commands without prefixing sudo.
$ docker run hello-world
That’s All!, You can now start working with Docker.
Docker Registry: http://registry.hub.docker.com/