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 resources, easy to manage and will always run the same regardless of the operating environment it is running in.
Docker uses cgroups and namespace to allow the independent containers to run within a single Linux instance.
Install Docker On Ubuntu 16.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.io docker-engine containerd runc
Contents such as images, volumes, and networks under /var/lib/docker/ are preserved.
Setup Docker Repository
Update the repository cache.
sudo apt-get update
Install the below packages to ensure the apt work with https method, and that CA certificates are installed.
sudo apt-get install -y apt-transport-https software-properties-common ca-certificates wget
Add the GPG key for the 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 /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 repositories.
sudo apt-cache policy docker-ce
You should see the output like below, should have Docker repository details.
docker-ce: Installed: (none) Candidate: 5:19.03.5~3-0~ubuntu-xenial Version table: 5:19.03.5~3-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages 5:19.03.4~3-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages 5:19.03.3~3-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
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 sudo systemctl enable docker
Run a docker container to verify the Docker installation
sudo docker run hello-world
You should see output like below; this confirms that Docker is correctly installed.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
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 docker commands with sudo. 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 the docker group, replace raj with your username.
sudo useradd -m raj
Add a user to the 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
Docker Basic Topics
Docker Advanced Topics
That’s All. Please share your thoughts in the comments section.