How to install Docker on Ubuntu 16.04
Docker is an open-source software that helps to deploy, run applications in a container. The containers are like a virtual machine but consume 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.
Note: Docker requires 64-bit operating system, and supports Ubuntu 16.04 / 16.10 and Ubuntu 14.04.
Docker is now available in two editions,
- Community Edition (CE)
- Enterprise Edition (EE)
Here, we will install Docker Comunity Edition (CE).
Uninstall older versions of Dockers, named “docker” or “docker-engine” along with associated dependencies. If your system does not have a docker package, skip the below step.
$ sudo apt-get -y remove docker docker-engine
Contents such as images, volumes, and networks under /var/lib/docker/ are preserved.
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 software-properties-common ca-certificates
Add the GPG key for Docker repository on your system.
$ wget https://download.docker.com/linux/ubuntu/gpg $ sudo apt-key add gpg
Now, add the official Docker repository by running the following command in the terminal.
$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" | 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-ce
You should see the output like below, should have Docker repository details.
docker-ce: Installed: (none) Candidate: 17.03.1~ce-0~ubuntu-xenial Version table: 17.03.1~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages 17.03.0~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable 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-virtual linux-image-extra-$(uname -r)
Now, install the Docker using the following command.
$ sudo apt-get -y install docker-ce
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.service $ 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 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 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 if it does not exist.
$ 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/