D

Docker is a software application that simplifies the process of managing the application process in the containers. The containers are similar to “” but containers are portable. This Docker is a most familiar software package developed by the Docker . The benefits of using Docker is that it shares the resources with kernel and makes it easy to process the applications inside the containers. Dockers don’t need any dedicated resources. Docker is available in two versions, they are Docker CE and Docker EE!

Docker CE means Consumer Edition and Docker EE means Enterprise Edition. If you are using this Docker for single user purpose and then we suggest you go with Docker CE. In this article, We clearly explained each important steps to install Docker in Ubuntu 18.04 LTS Bionic Beaver Edition.

Jump To:

Prerequisites:

You just need the server setup running in Ubuntu 18.04 with superuser authority and Firewall enabled. You just need to uninstall or remove the older versions of Docker from your server. The older versions of Docker are called as docker, docker.io, or docker-engine. The below command will remove all the older versions.

$ sudo apt-get remove docker docker-engine docker.io containerd runc

It’s OK! if apt-get reports that none of these packages are installed.

Installing Docker Application in Ubuntu 18.04:

There are two ways to install the Docker application in Ubuntu 18.04 server, They are:

Install Docker on Ubuntu using Default Repo:

The first step is updating your system to the current.



$ sudo apt-get update

The above command will update your system. Then you need to uninstall the older version of Docker { skip if you followed this step as we mentioned in Prerequisites }. Then follow the below step to install the Docker application.

Install Docker Application Command:

$ sudo apt install docker.io

The above command will initiate the installation process of Docker application in your Ubuntu Server.

Initiate & Automate Docker:

By default, The Docker app is not running on startup and so you need to set the application to run in startups.

$ sudo systemctl start docker $ sudo systemctl enable docker

That’s it, The Docker application has been installed using default repositories. But we recommended the below method to install the Docker on Ubuntu 18.04. Let us get into the detailed methods for installing this Docker application.

Install Docker from Official Repository:

The Docker package available in the default repository may be an outdated version and so we recommend you use the official Docker repo to install the latest version. Here we explain the detailed steps for installing the Docker app for Ubuntu 18.04

Step1- Update your existing packages:

$ sudo apt update

Installation Process:

Now install a few prerequisite packages which let over HTTPS:

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common



Then add the GPG key for the official Docker Repository to your system.



$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -



By executing the above command you will get an output as “OK“, means you are good to go.

Now you need to add the Docker repo to the APT sources:



$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

Once it got completed, kindly update all the packages.

$ sudo apt update

Now you need to ensure that you are installing the Docker from the official Docker repo instead of Ubuntu repo.

$ apt-cache policy docker-ce

The docker-ce means ” Docker Consumer Edition “. Execute the above command and you will get output like below.

Output: docker-ce:

Installed: (none)

Candidate: 18.03.1~ce~3-0~ubuntu

Version table:

18.03.1~ce~3-0~ubuntu 500

500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

From the output, you may able to see that Docker is not installed but the candidate for installation is from the Docker repository for Ubuntu 18.04.

Now all the before steps are completed, Install the Docker Application:

$ sudo apt install docker-ce

Once the installation has been completed successfully. Kindly enter the below command to check the Docker version.



$ docker --version

The above version is the latest version of Docker installed from the official Docker Repo.

Launching the Docker Application:

After the installation process, You need to assign the sudo power to the Docker group. By default, The Docker command can run only by the root admin only. If you try to access the Docker group without “sudo” it will throw you the error. If you are not the member or admin of the Docker group and then it will throw you the error.

Output: docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?. See ‘docker run –help‘.

You can simply avoid this error by calling the docker group with “sudo” command or adding the user has admin privileges to the docker group.

$ sudo usermod -aG docker ${USER}

The above command will add you to the Docker group with admin privileges.

To apply for the new group membership, log out of the server and back in and type the following command.

$ su - ${USER}

Then confirm the process that you adding the new user to the Docker group.

$ id -nG

Using the Docker Application:

To view all available commands of Docker:

$ docker

As of Docker 18.09 version, the below list of commands is available.

Output: attach - Attach local standard input, output, and error streams to a running container

build - Build an image from a Dockerfile

commit - Create a new image from a container's changes

cp - Copy files/folders between a container and the local filesystem

create - Create a new container

diff - Inspect changes to files or directories on a container's filesystem

events - Get real-time events from the server

exec - Run a command in a running container

export - Export a container's filesystem as a tar archive

history- Show the history of an image

images - List images

import - Import the contents from a tarball to create a filesystem image

info - Display system-wide information

inspect- Return low-level information on Docker objects

kill - Kill one or more running containers

load - Load an image from a tar archive or STDIN

login - Log in to a Docker registry

logout - Log out from a Docker registry

logs - Fetch the logs of a container

pause - Pause all processes within one or more containers

port - List port mappings or a specific mapping for the container

ps - List containers

pull - Pull an image or a repository from a registry

push - Push an image or a repository to a registry

rename - Rename a container

restart- Restart one or more containers

rm - Remove one or more containers

rmi - Remove one or more images

run - Run a command in a new container

save - Save one or more images to a tar archive (streamed to STDOUT by default)

search - Search the Docker Hub for images

start - Start one or more stopped containers

stats - Display a live stream of container(s) resource usage statistics

stop - Stop one or more running containers

tag - Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

top - Display the running processes of a container

unpause- Unpause all processes within one or more containers

update - Update configuration of one or more containers

version- Show the Docker version information

wait - Block until one or more containers stop, then print their exit codes





$ docker info

The above command will provide overall information {system wide}.

Working with Docker Images:

Docker containers are built from Docker images and by default, Docker pulls the images from the official Dockers hub. These Docker hubs are also managed by the Docker company. The Docker hub allows anyone to host their Docker images.

To check whether you can access from Docker Hub:

$ docker run new-world

The following output will appear on your screen:

Output: Unable to find image ‘new-world:latest‘ locally

latest: Pulling from library/new-world

9bb5a5d4561a: Pull complete

Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d

Status: Downloaded newer image for new-world:latest Hello from Docker!

This message shows that your installation appears to be working correctly.

…

The output message simply says that Docker was unable to find the new-world image. So it downloaded the image from Docker hub. Once the image has been downloaded, then the application inside the container will execute and the result will be displayed.

Searching for Docker Images:

You can search for Docker images inside the Docker hub with the help of a “search” command.



$ docker search ubuntu

The list of Docker images will appear in your screen as shown in below image.

You can download the Docker images using the “pull” command. The OK represents the image built and supported by Docker hub.

$ docker pull ubuntu

The above command will download the Ubuntu image to your computer.

To see the downloaded Docker images in your computer:

$ sudo docker images

Managing Docker Images:

In this managing area, we will explain you that how to “Stop, Start & Attach”

Starting your Docker Container:

$ docker start Container_ID

The above command will start your Docker container.

Stoping your Docker Container:

$ docker stop Container_ID

The above command will stop your Docker container.

Attaching your Docker Container:

$ docker attach Container_ID

The above command will attach your Docker containers.

Uninstalling Docker on Ubuntu 18.04:

To uninstall the Docker application from Ubuntu 18.04, execute the following command:

$ sudo apt-get purge docker-ce

Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes execute the following command:

$ sudo rm -rf /var/lib/docker

The above command will remove all Docker images, container and volumes. But you must delete any edited configuration files manually.

Verdict:

That’s it. In this article, we clearly explained the information about installing the Docker on Ubuntu 18.04 LTS. You need to follow the installation steps carefully. Docker is the application to manage the process inside the container. If you have any queries and then comment on us or create a question in our Forum.