Kuberty.io
  • blog
Kuberty.io

Install Docker

Home / Install Docker
18Apr

How to Install Docker on Ubuntu 18.04?

April 18, 2022 admin Docker, Ubuntu

If you’re a part of the ever-growing IT realm, you must have heard words like containerization and Docker. It’s a known fact that many IT personnel have begun opting for Docker today. Docker is an awesome tool for developing, deploying and managing apps with ease. In fact, it makes the bothersome process of container deployment pretty effortless. Many industry biggies like Spotify, ING, The New York Times, PayPal, The Washington Post, and many others, have embraced Docker wholeheartedly because of the increased convenience it offers. You, too, can install Docker on Ubuntu 18.04 for personal use. Fret not if you aren’t informed about the installation steps. This tutorial seeks to handle that aspect. Read on.

Why Install Docker on Ubuntu 18.04?

Now, you might be pondering about the need for installing Docker on your Ubuntu PC. Well, here are some of Docker’s amazingly cool features. Check them out:

  • Return on Investment (ROI) is perhaps its foremost feature. This leads to Docker being capable of cutting costs and efficiently boosting profits. All companies strive to generate steady profits over a long period. Docker can be their solution in this regard.
  • Docker makes its users capable of constructing a container image (CI) and utilizing it anywhere and anytime during the deployment process. Thus, it enables users to isolate non-dependent steps and execute them side by side.
  • Another great feature of Docker is its facility of rapid deployment. It can reduce the deployment time drastically. This happens because Docker tends to generate a spate container for each process and ditches OS boots. Hence, one can build or demolish info without the fear of reintroducing it at a greater cost than what’s considered reasonable.
  • Docker supports multiple platforms. Such multi-platform support leads to increased portability. Users can run Docker containers on Rackspace, Amazon (ECC) Elastic Cloud Computing, DigitalOcean, Google Compute Engine, Microsoft Azure, and many others. So, a container running on one platform can be ported to another. For instance, one could port a container running on Rackspace to Amazon ECC and vice-versa.

Steps to Install Docker on Ubuntu 18.04

Now, let’s focus on our foremost concern, that is, installing Docker on our Ubuntu 18.04 computer. Here we’re taking Docker Community Edition. But first, we need to accomplish a few prerequisites.

Prerequisites

  • A Ubuntu 18.04-installed server
  • A valid Docker Hub account

Step 1. Install Docker CE

While installing the Docker software, many people’s first instinct is to install it from the official Ubuntu repository. But we suggest you ditch that practice. Why? Because most of the time, the Docker installation package you get from there wouldn’t be the latest edition. So to make sure your Docker software is the latest, you have to install it from the Docker repository. For that purpose, you must attach a new package source and verify the validity of downloads by attaching a GPG key from Docker. Only after that should you proceed to install it.

So, first, you got to update your current package list:

sudo apt update

Next, install a few essential packages which will allow apt employ packages on HTTPS:

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

Then, you have to attach the GPG key we talked about earlier to the Docker repository:

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

Now, attach the Docker repository to apt sources:

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

After doing so, you need to update the package DB from the repository you just attached:

sudo apt update

Like we said earlier, ensure the successful installation of packages from the Docker repository instead of the official Ubuntu repository:

apt-cache policy docker-ce

Once finished, you should see an output as given below:

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

Here, you’d find the Docker CE file isn’t installed yet. It’s a confirmation of the fact that the installation contender comes from the Docker repository.

Now, you got to install the Docker CE file:

sudo apt install docker-ce

It will install Docker CE on your local machine with daemon enabled. Also, the service will now start with each reboot. You may verify its status by executing this command:

sudo systemctl status docker

If everything is fine, you will receive this output stating that the service is up and running:

docker.service – Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)

Active: active (running) since Thu 2018-07-05 15:08:39 UTC; 2min 55s ago

Docs: https://docs.docker.com

Main PID: 10096 (dockerd)

Tasks: 16

CGroup: /system.slice/docker.service

├─10096 /usr/bin/dockerd -H fd://

└─10113 docker-containerd –config /var/run/docker/containerd/container.to ml

Now that you’ve installed Docker, you get both the daemon as well as the Docker client. Later in this tutorial, we will teach you about utilizing this command. For now, proceed to the next step.

Step 2 (optional). Execute the Docker Command Minus the sudo

Typically, one can run the docker command only if they possess root access or are a part of the docker group. This group gets constructed while you’re installing the Docker tool. Now, in case you try to run this docker command without fulfilling either of these two conditions, you’re bound to receive an output like this:

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.

See ‘docker run –help’.

So what to do? Well, to ditch the need of typing sudo every time you attempt at running the docker command, execute the below-given command to specify your username to your docker group:

sudo usermod -aG docker ${USER}

To finalize your group initiation process, you got to sign out of your server and run this command:

su – ${USER}

After doing that, you’d be asked to provide your user password before you can proceed further.

You need to authenticate the addition of your user to the docker group. For doing so, use this command:

id -nG

Suppose you plan on adding a user to your Docker group that’s not a part of it. Then, you got to define the concerned username using the below command:

sudo usermod -aG docker username

We will proceed, presuming that you’re running the docker command as a Docker group member from now on.

So, that being said, let us now delve deep into the docker command.

Step 3. Utilize the Docker Command

The docker command utilization comprises a series of commands, options, and arguments. The syntax could usually be found in the following form:

sudo usermod -aG docker username

By utilizing the command below, you can see all your accessible subcommands:

docker

As of now, the list of available subcommands is as follows:

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

Now, if you wish to see the options obtainable on a particular subcommand, utilize this:

docker docker-subcommand –help

You are also capable of viewing your Docker’s system info by simply typing this command:

docker info

Let us focus on some of these subcommands. We will utilize Docker images first.

Step 4. Begin Working with Docker Images

Docker images are essential for constructing Docker containers. Typically, Docker gathers all these images from the cloud-based repository Docker Hub, which is managed by Docker. Everybody is capable of hosting their images on this repository. Therefore, the chance is always high that you’d find the images of all your necessary apps and Linux distributions on Docker Hub.

To ensure your eligibility to navigate to Docker Hub and download your required images, utilize this command below:

docker run hello-world

If your eligibility status is positive, you will get an output like this:

Unable to find image ‘hello-world:latest’ locally

latest: Pulling from library/hello-world

9bb5a5d4561a: Pull complete

Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d

Status: Downloaded newer image for hello-world:latest

Hello from Docker!

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

Originally, Docker couldn’t find the hello-world image in your local storage. Therefore, it downloaded that image. After the completion of the download, Docker built a new container utilizing the newly downloaded image. It also constructed the app inside that container. Hence, the message.

You can look for the images you need utilizing the docker command + search subcommand. For instance, execute the following command if you’re trying to find the Ubuntu image:

docker search ubuntu

Doing so will take the script to Docker Hub and show all the available image names matching the search string. So, you will receive the below output:

NAME DESCRIPTION STARS OFFICIAL AUTOMATED

ubuntu Ubuntu is a Debian-based Linux operating sys… 7917 [OK]

dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 193 [OK]

rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 156 [OK]

ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 93 [OK]

ubuntu-upstart Upstart is an event-based replacement for th… 87 [OK]

neurodebian NeuroDebian provides neuroscience research s… 50 [OK]

ubuntu-debootstrap debootstrap –variant=minbase –components=m… 38 [OK]

1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 36 [OK]

nuagebec/ubuntu Simple always updated Ubuntu docker images w… 23 [OK]

tutum/ubuntu Simple Ubuntu docker images with SSH access 18

i386/ubuntu Ubuntu is a Debian-based Linux operating sys… 13

ppc64le/ubuntu Ubuntu is a Debian-based Linux operating sys… 12

1and1internet/ubuntu-16-apache-php-7.0 ubuntu-16-apache-php-7.0 10 [OK]

1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10 ubuntu-16-nginx-php-phpmyadmin-mariadb-10 6 [OK]

eclipse/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 6 [OK]

codenvy/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 4 [OK]

darksheer/ubuntu Base Ubuntu Image — Updated hourly 4 [OK]

1and1internet/ubuntu-16-apache ubuntu-16-apache 3 [OK]

1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4 ubuntu-16-nginx-php-5.6-wordpress-4 3 [OK]

1and1internet/ubuntu-16-sshd ubuntu-16-sshd 1 [OK]

pivotaldata/ubuntu A quick freshening-up of the base Ubuntu doc… 1

1and1internet/ubuntu-16-healthcheck ubuntu-16-healthcheck 0 [OK]

pivotaldata/ubuntu-gpdb-dev Ubuntu images for GPDB development 0

smartentry/ubuntu ubuntu with smartentry 0 [OK]

ossobv/ubuntu

…

Notice the output carefully. The “[OK]”s in the “OFFICIAL” section of the output signifies images that the organization behind the project made and endorsed. Once you’re finished picking the image of your preference, utilize the pull subcommand for downloading it to your PC.

Thus, you can run the following command for downloading the Ubuntu image:

docker pull ubuntu

Once downloaded, you will get the following output:

Using default tag: latest

latest: Pulling from library/ubuntu

6b98dfc16071: Pull complete

4001a1209541: Pull complete

6319fc68c576: Pull complete

b24603670dc3: Pull complete

97f170c87c6f: Pull complete

Digest: sha256:5f4bdc3467537cbbe563e80db2c3ec95d548a9145d64453b06939c4592d67b6d

Status: Downloaded newer image for ubuntu:latest

After downloading an image, you are free to execute the run subcommand for creating a container from your downloaded image. As the hello-world instance might’ve made you comprehend, if an image download fails to occur even after executing the docker command + run subcommand, the Docker client will initially download that image. And, after that, it will create a container utilizing the same.

Your downloaded images could be viewed by executing this simple command:

docker images

The output you will get should something like this:

REPOSITORY TAG IMAGE ID CREATED SIZE

ubuntu latest 113a43faa138 4 weeks ago 81.2MB

hello-world latest e38bc07ac18e 2 months ago 1.85kB

In case you didn’t know, you can modify the images you utilize for the container running. Also, it’s possible to use them for constructing new images, capable of being uploaded to Docker Hub or other similar repositories whenever you please.

So, the next step will dig deeper into this container running matter.

Step 5. Run a Docker Container

Remember the hello-world container you executed earlier? That was a perfect instance of a container that is capable of running and exiting after releasing a demo text. Containers, as you may know, have many other usages. Such a fact shouldn’t come as a surprise as they’re pretty much like VMs, albeit with increased resource-friendliness.

For instance, run a container utilizing the newest Ubuntu image. The below command could give you interactive shell access:

docker run -it ubuntu

Next, try to reflect in your command the fact that your work is occurring within that container. Therefore, make it look something like this:

root@d9b100f2f636:/#

Notice the container ID here. Remember it because we will need it later for container identification provided that you’ve decided to delete it.

With that, you’ve now become capable of running any command you wish to within your container. Let us take the task of package DB update inside the container as an instance. As you are a root user within your container, you don’t have to type sudo before your command:

root@d9b100f2f636:/#

After that, install any app of your preference inside it. For now, we will be installing Node.js:

root@d9b100f2f636:/#

Doing so will help install Node.js in your container. After the installation process is over, you got to verify Node.js’s installation with this command:

root@d9b100f2f636:/#

The output you will get from here will state the version of your newly installed Node.js:

v8.10.0

Remember that anything you modify inside the container applies to that container only.

Now enter exit in the command-line to exit your container.

Step 6: Manage Docker Containers

This step is about the container management aspect. After you install Docker on Ubuntu 18.04 and use it for a while, you’ll find tons of both active and inactive containers stowed on your PC. You can view the active containers list using the command given below:

docker ps

After doing so, you will get the below output:

CONTAINER ID IMAGE COMMAND CREATED

You have begun two containers till now from the hello-world and Ubuntu images. While they are in an active state at present, they still occupy some space in your PC.

You can also view both the active and inactive container list at once by executing the following command:

docker ps -a

You will ten to one receive the below output:

d9b100f2f636 ubuntu “/bin/bash” About an hour ago Exited (0) 8 minutes ago sharp_volhard

01c950718166 hello-world “/hello” About an hour ago Exited (0) About an hour ago festive_williams

Executing the below command will permit you to view your most recent container:

docker ps -l

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

d9b100f2f636 ubuntu “/bin/bash” About an hour ago Exited (0) 10 minutes ago sharp_volhard

You can restart a container that has stopped by implementing docker start and then, your docker ID. Here we will use a Ubuntu-based container:

docker start d9b100f2f636

Once the container gets started, you can check its status by using docker ps:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

d9b100f2f636 ubuntu “/bin/bash” About an hour ago Up 8 seconds sharp_volhard

Now, if you want to stop a container from running, you have to implement docker stop and then, the container ID. Here, we will opt for the Docker-provided container name, that is, sharp_volhard:

docker stop sharp_volhard

If you ever feel that you no longer need any particular container, you can eliminate its existence simply by utilizing the docker rm + container ID combo. Suppose you don’t know the hello-world-related container name, you can use docker ps. This command will aid you in finding the container ID you’re looking for:

docker rm festive_williams

The –name switch can be utilized in initializing and naming a container. Also, there is the –rm switch for generating a self-removing container upon stoppage. For further info regarding these options and facilities, you may run the docker run help command.

You can turn your containers into images. These images can then be utilized for creating new containers.

Step 7. Make Modifications in a Container to a Docker image

While dealing with a Docker machine, you are capable of generating, changing, or removing files exactly like a VM. Any modification you make will only be confined to that container. You are free to initialize or eliminate it. But if you utilize the docker rm command, you won’t be able to recover them.

Once you install Node.js within your Ubuntu container, you possess a running container using an image. However, the created container and the source image are different. But you can base new images on this Node.js container afterward.

Next, modify a new Docker image using the following command:

docker commit -m “What you did to the image” -a “Author Name” container_id repository/new_image_name

The command specifies both the changes you committed as well as the ID of the author. Do you remember the Container ID you came across during the initial stages of your Docker session? Unless you made extra repositories to the Docker Hub, your username is your repository. Here’s how the command will be like:

docker commit -m “added Node.js” -a “sammy” d9b100f2f636 sammy/ubuntu-nodejs

Once you implement an image, that image gets stowed in your local machine.

Using the below command again to list images will help you view both the latest image as well as the source it came from:

docker images

The output you receive would be like this:

REPOSITORY TAG IMAGE ID CREATED SIZE

sammy/ubuntu-nodejs latest 7c1f35226ca6 7 seconds ago 179MB

ubuntu latest 113a43faa138 4 weeks ago 81.2MB

hello-world latest e38bc07ac18e 2 months ago 1.85kB

In the above instance, the latest image is labeled as “ubuntu-nodejs” that came from the source Ubuntu image. There is also a noticeable difference between their size that is a sure shot indicator of the modifications. This instance reflects the addition of Node.js installation as a change.

You can also construct an image from the Docker file. It allows you to auto-install software in a new image. However, it isn’t really our focus here.

Step 8. Route Docker Images to a Docker Repository

The last thing you have to get done is to create an unhackneyed image from an already extant one and share it with others. These include a select few of your buddies, on Docker Hub, or some other Docker repository accessible to you.

Utilize the below command to sign in to your Docker Hub account:

docker login -u docker-registry-username

Next, enter your Docker Hub when asked. If entered right, your sign-in would be triumphant.

In case your Docker repository username and the name you utilized while generating the image differ, make things right by tagging your repository username with your image. Execute this command:

docker tag sammy/ubuntu-nodejs docker-registry-username/ubuntu-nodejs

After doing so, you may start routing your image:

docker push docker-registry-username/docker-image-name

For routing the ubuntu-nodejs to your repository, type:

docker push sammy/ubuntu-nodejs

If successful, an output would state that clearly:

The push refers to a repository [docker.io/sammy/ubuntu-nodejs]

e3fbbfb44187: Pushed

5f70bf18a086: Pushed

a3b5c80a4eba: Pushed

7f18b442972b: Pushed

3ce512daaf78: Pushed

7aae4540b42d: Pushed

Also, you would be able to see that image name on your dashboard.

Nonetheless, if the received output looks like the following one, maybe you didn’t sign in:

The push refers to a repository [docker.io/sammy/ubuntu-nodejs]

e3fbbfb44187: Preparing

5f70bf18a086: Preparing

a3b5c80a4eba: Preparing

7f18b442972b: Preparing

3ce512daaf78: Preparing

7aae4540b42d: Waiting

unauthorized: authentication required

In that case, utilize docker login and perform the procedure again. Then, navigate to your Docker Hub registry page’s dashboard and see whether the image name appears there or not.

And that’s all. Your quest to install Docker on Ubuntu 18.04 is over.

Conclusion

To conclude, the Docker tool is capable of resolving a very common issue of deploying containers or containerized apps that is rampant among almost all IT people. Docker could be a great lifesaver to you if you struggle with a container or containerized app deployment too. Being pretty much a VM, you can run any image you please using this wonderful software. The best thing about Docker is perhaps its open-source facilities that make way for continual updates and constant improvements by an amazingly dedicated community.

Also, as you can see from the entire article, you can install Docker on Ubuntu 18.04 with ease. The procedure is pretty simple. However, losing track of the to-be-followed steps mentioned above could ball things up badly. That’s why it’s crucial to go through the tutorial religiously and then, execute each step with utmost care. From installing the Docker Community Edition software to routing Docker images to a Docker repository – only the proper execution of every step could guarantee the success of their Docker installation. Now that you comprehend what to do and how to do so, you can install Docker on your Ubuntu-installed PC with ease. All the best for testing your knowledge.

Read more
07Feb

How to Install Docker on Linux?

February 7, 2021 admin Docker, Linux

Docker is an emerging technology that is gaining popularity around the world. It is a containerization platform that helps you to build and deploy container-based applications on different platforms.

With Docker, you can easily break down the complex applications into microservices stored within a container. You can deploy these containers on various platforms without worrying about the underlying system specifications.

Docker leads to less resource consumption as it shares the underlying OS kernels. If you are an IT operations professional, then you might understand the benefit of implementing Docker technology within the DevOps lifecycle through the software development phase.

Disadvantages of VMs and the Emergence of Docker

Earlier, virtual machines solved the requirement of running various applications isolated from each other but resulted in high-resource consumption and were also hard to handle. Docker came into the picture and solved the shortcomings of VMs.

You can run Docker efficiently either on-premises, over the public cloud, or in a hybrid setup. Docker is based on containers, images, volumes, and networks that can be run on the same host without interfering with each other’s work. Handling multiple containers at the same time has become more comfortable with various tools from Docker and third-parties.

Docker is an open-source project which comes with a large, expanding community support. It has been available since 2013. Over its run, Docker has provided immense growth to the containerization and microservices concepts.

Docker displays cross-platform compatibility. In this article, we will learn how to install Docker on Linux. Before going into that, let us first know the prerequisites for installing Docker on Linux.

Basic Prerequisites for Installing Docker on Linux

With this article, you will be able to install Docker simply. But you must fulfill the necessary system requirements to start with the process, which are:

  • Ubuntu 18.04 or newer 64-bit version.
  • Create a user account with sudo privileges for Ubuntu to run the Docker commands.
  • If you do not have basic command-line knowledge, groom yourself with basic command-line/terminal knowledge.
  • Navigate to the Terminal (CTRL-ALT-T or Applications menu > Accessories > Terminal) for running Docker commands, like installing and setup.
  • You should have a Docker repository that will store the Docker software (OPTIONAL).

How to Install Docker on Linux?

If you have installed Docker on your system already, please check and confirm that the Docker’s installation package version is the latest.

If the installed Docker software is not the latest one available, then you should try installing the latest version from the Docker repository. Once you confirm the version, you can simply start with the below-mentioned steps:

Step 1 – Updating the Docker packages

To update the Docker system and packages, you have to run the following commands:

sudo apt update

sudo apt upgrade

Having an updated system will provide a compatible environment to run further commands in Docker.

Step 2 – Deleting the Docker’s older version

If you have the older version of Docker installed on your system, you can run the below command to get rid of it:

sudo apt-get remove docker docker-engine docker.io

Step 3 – Install the Docker prerequisite packages

You should have the proper Docker package to extract the Docker files and related installation details. For downloading the required Docker package, you can run the below command:

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

where,

  • apt-transport-https –> It will use the https secured connection to transfer the required files and data.
  • ca-certificates –> It will confirm the validity of the security certificates for the web browser and your machine
  • curl –> It will transmit the data needed
  • software-properties-common –> You can add the script using this parameter to manage the software.

Step 4 – Adding GCP key for Docker

You can add the Docker’s GCP key using the command below:

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

A demonstration of the same is:

Adding GCP key for DockerStep 5 – Docker repository is added to the APT resources

If you want to use the official method to install the Docker, then you should add the latest Docker repository to the resources. You can run the following command to ensure that:

sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

You will see something like this:

Docker repository is added to the APT resources

Step 6 – Running the package database update

Once you update the repository, you can update the list of packages with the help of the latest updates repository. If you want to update your package database, you can run this command:

sudo apt update

Step 7 – Checking and Confirming the Docker repository

With the below command, you can make sure that you are installing the Docker repository rather than the Ubuntu default repository:

apt-cache policy docker-ce

After running the above command, you will get the following output, of course, with a different version number:

Checking and Confirming the Docker repositoryStep 8 – Running the Docker installation command

With the following command, you can install the latest version of Docker on your system:

sudo apt install docker-ce

But if you want to install a particular version of Docker, you can run the below command in the terminal window:

apt-cache madison docker-ce

You’ll get a screen like this:

Running the Docker installation commandOnce you run the above command, you will get a list of the available Docker versions. Now you can run the below command with the particular version of Docker that you want to install on your system:

sudo apt-get install docker-ce=[version]

For example:

sudo apt-get install docker-ce=[version]

Step 9 – Checking the running Docker version

To confirm the installed version of the Docker on your system, run the following command:

sudo systemctl status docker

Step 10 – Starting the Docker version installed on your system

To start the installed version of the Docker on your system, run the following commands:

sudo systemctl start docker

sudo systemctl enable docker

Starting the Docker version installed on your system

Step 11 – Confirming the Docker’s version

Docker comes with a command that allows you to check and confirm the installed Docker’s version, this is:

docker –version

docker --version

Steps to Install Docker Using a .deb Package

To install the Docker manually, you can install it from the .deb file. Here’s how to do it:

  • Step 1 – Go to the Docker download page.
  • Step 2 – Navigate to pool -> stable -> amd64. This amd64 will indicate the stable Docker release for Ubuntu 18.04 version.

Install Docker Using a .deb Package

  • Step 3 – Once you select the Docker engine, the .deb package will get downloaded automatically. Make sure you save the path of the file downloaded.
  • Step 4 – The below command allows you to download and start the Docker installer:

sudo dpkg -i /path/to/docker.package.deb

Once you run the aforementioned command, the installer will start the process of installing Docker on your system with Ubuntu.

Install Docker With the Help of a Convenience Script

You can also install the testing version of Docker using a convenience script. This installation method, however, will not work if you are working in the production environment or if you already have Docker installed on your system.

Check and confirm the script before you download and run it. Once you get the script from the above-mentioned link, run the following command:

curl -fsSL https://get.docker.com -o get-docker.sh

Run the following command to start the installation process of Docker:

sh get-docker.sh

Running the Docker Commands without Sudo Access

You can work with the root user or the Docker group user to run the terminal Docker commands. While installing, the group user will be created automatically. If you run the command without using the sudo access or the group user, you will get the below output, for instance:

docker container run hello-world

docker container run hello-world

You will get the error unable to find the image. You have to add the working user to the Docker group to avoid the error. You can add the user by running the below command:

sudo usermod -aG docker ${USER}

You have to logout and then login back again to allow the changes to take effect.

Start the Docker on your System

Once you are done with the Docker installation, you should now check running the test image using the below command:

sudo docker run hello-world

As you install Docker, you will have some images on your Docker repository. You can check the available Docker images using the below commands:

sudo docker search [search_query]

sudo docker search ubuntu

sudo docker search ubuntuWith the help of the above command, you can search for a particular image present in the Docker hub. It will display the list of all the Docker images that match the provided image string.

Docker comes with a command that helps you to pull the image to your local machine. You can run the following command that will specify the image name, and the latest image will get pulled, if available:

sudo docker pull ubuntu

sudo docker pull ubuntu

Once you have pulled the image, it will help you run the container with this command:

docker run ubuntu

There are several images available. To pull every image on your machine, you can run the following command:

sudo docker images

Conclusion

Now you will be able to successfully install and run Docker on your system. With this blogpost, you get to know some essential Docker commands working with images. After reading it, you can easily install Docker on your Linux distribution, which, in this case, is Ubuntu 18.04.

If you have a basic knowledge of the command-line, you will get through the Docker installation instructions easily without making a considerable effort. Post Docker installation, you can get started with creating and deploying Docker applications. All the best!

Read more
25Jan

How to Install Docker in Ubuntu?

January 25, 2021 admin Docker, Ubuntu

Docker is one of the most popular software when it comes to creating containers for application development. While dockers share the same idea as that of virtual machines, they offer better flexibility.

Docker can readily speed up the entire application as it requires very few resources from the host’s kernel. In this tutorial, we are going to discuss how to install Docker in Ubuntu. You will learn the various ways to install Docker Engine and use it in the safest ways.

Prerequisites

Supported OS

You can easily install Docker Engine on any of the following 64-bit versions of Ubuntu:

  • Ubuntu Groovy 20.10
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)
  • Ubuntu Xenial 16.04 (LTS)

Storage Drives

Storage drives that are supported on Ubuntu include opverlay2, btrfs, and aufs.

Docker Hub Account (Optional)

Although having a Docker Hub account is completely optional, it is required if you want to publish your own images on it.

Installation Methods for the Docker Engine

Mainly, you can install Docker Engine on Ubuntu in one of the following 3 ways:

  1. A majority of the users go with installing Docker via the repository. It offers a seamless installation process without any hassles.
  2. If you want to take more control over the installation process, there’s always the option for downloading the DEB file. Once you have downloaded the file, you can install it in systems without an active internet connection.
  3. If you want to install the under-testing version for the development environment, you can always use the convenience script.

1. Installing Docker using the Repository

Setting up the repository is the prime thing that you need to do before installing your Docker Engine. You can install or update. Only after that, Docker can be installed from the repository. Here is the process to set up the Docker repository:

Step #01 – You need to update the apt package and install the apt. The apt command ensures that the repositories can take over the standard HTTPS installation.

$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

Step #02 – After that, you need to add Docker’s GPG key as:

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

Step #03 – After that, you need to verify it. That verification will provide you with the key to the fingerprints. 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88. You need to add only the last eight characters.

$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
  9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid  [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]

Step #04 – After that, you need to build a stable repository by using the following command. If you want to add the test repository, you must replace the word stable with the test.

Also, you need to note that the subcommand which is stated below returns your Ubuntu distribution. Docker does not hold any guarantee for the untested distributions.

$ sudo add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 $(lsb_release -cs) \
 stable"

This is for amd64. For deb_armhf and deb_arm64, you need to replace amd64 in the command with the one you want.

Installing the Docker Engine

Well, installing a Docker Engine can be done by installing the latest version after updating the apt package.

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Also, if you have multiple repositories installed, then the most recent version of the Docker Engine will automatically be installed. You need to follow the following steps to install a specific version:

Step #01 – While installing a specified version, you can always look at the available repositories. After that, select and install.

$ apt-cache madison docker-ce
 docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 18.06.1~ce~3-0~ubuntu  | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 docker-ce | 18.06.0~ce~3-0~ubuntu  | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
 ...

Step #02 – Select the column from which you wish to install a specific version.

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

Step #03 – You can always run the hello world image to properly check the installation.

$ sudo docker run hello-world

It will run in a container. After that, it will print a piece of information and exit.

Note: Docker Engine is now installed and running. Even after creating the docker group, you need to add users. For other configurational steps, and to allow a non-privileged user to run the Docker Commands, you need to proceed to Linux post-install.

How to Upgrade the Docker Engine?

To upgrade, you need to run sudo apt-get update, and after that, you need to follow the installation instructions and choose the new version to install.

2. Install from a Package

You can also install the Debian (DEB) file and install it manually without using the Docker repository. Proceed further with the following steps:

Step #01 – Go to https://download.docker.com/linux/ubuntu/dists/ and choose your Ubuntu version.

Step #02 – Browse to pool/stable/ and choose amd64, arm64 and armhf.

Step #03 – Download and install the .deb file for the corresponding version. If you need to install the test package, change the word ‘stable’ from ‘test’. After that, you need to change the below path to the directory of the downloaded Docker package.

$ sudo dpkg -i /path/to/package.deb

This will automatically start the Docker daemon.

Step #04 – Run the hello world script in order to verify the installation process.

$ sudo docker run hello-world

This will run a container. While running, it will print an informative message and exit.

Now that, you have got your Docker engine installed, but no user is added to the newly created docker group. In this case, you need to proceed to the Linux post-installation steps for further configurations.

Upgrading the Docker Engine

You need to install new files every time to install the latest Docker Engine and need to repeat the same installation process with the new file.

3. Install via a Convenience Script

You can install Docker Engine from the convenience scripts provided by Docker. You can get the scripts from get.docker.com and test.docker.com.

You can always go with these scripts to install either edge or testing versions. But it has its risks, and you need to understand them before opting to install. It is always advised to run these scripts in development environments. The risks are:

  • You need to cautiously audit the scripts as they need sudo privileges to run.
  • Scripts will tend to configure your Linux distribution system.
  • The scripts will always install the current version. There’s nothing you can do about it.
  • You must not use the scripts if your host machine has Docker preinstalled.
  • It can install a large number of the packages as it does not ask for confirmation.

The following is a script that will install the Docker Engine. You should always examine the scripts. If you want a test version, replace ‘get’ with ‘test’.

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

<output truncated>

You can always add users to the Docker group with the following command:

sudo usermod -aG docker <your-user>

It will take effect after you log out and log back in. Now the Docker Engine community is created and it will start on a .deb based distribution.

For RPM-based distribution, you should use commands like systemcl or service. You can’t run the Docker command without admin privileges.

Upgrade the Docker Engine

You can upgrade your Docker Engine using your package manager directly. If you re-run the convenience scripts, it will re-install the previously installed repositories.

Uninstalling the Docker Engine from Ubuntu

In case you do not want Docker Engine on your Ubuntu device, you can remove it by following these steps:

Step #01 – You can use the below command to uninstall Docker Engine on Ubuntu

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io

Step #02 – You have to manually delete the remaining images and the containers. In case, you have edited any configuration files; you need to delete them manually as well.

$ sudo rm -rf /var/lib/docker

Final Takeaway

That was all about how to install Docker on Ubuntu. You can easily choose among the 3 aforementioned ways to get started with Docker on your Ubuntu-based device.

Ensure to pay close attention to the above-mentioned steps, and you can easily install Docker Engine on your system running Ubuntu. Leveraging Docker for DevOps technologies will deliver you a seamless workflow. So, all the best!

How to Install Docker in Ubuntu?

Read more
corporate-one-light
+1 800 622 22 02
info@scapeindustries.com

Company

Working hours

Mon-Tue

9:00 – 18:00

Friday

9:00 – 18:00

Sat-Sun

Closed

Contacts

3 New Orchard Road
Armonk, New York 10504-1522
United States
915-599-1900

© 2021 Kuberty.io by Kuberty.io