How to install and use Docker and its containers in Ubuntu

Docker on Ubuntu

Docker is an open source project supported by a business entity with the same name that makes it much easier to run an application process within a relatively isolated environment called Containers or container. Unlike a virtual machine (VM) that has its own kernel, a container depends on the host operating system's kernel, allowing it to be lighter and run much faster.

Docker is the simplest tool that it gives to our computer enterprise application development and management capabilities. By default, Docker containers are run using application images that are hosted on Docker Hub, where we can access from this link. In this article we will show you how to install and use these containers in Ubuntu and other distributions based on the operating system developed by Canonical.

Installing Docker on Ubuntu

The best thing if our intention is to always have the latest version of a software is to install the official repository of the software in question. To do this, we will follow these steps:

  1. First we open a terminal and import the GPG key of the software with the following command:
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  1. Next, we add the official repository:
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
  1. We update the packages:
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
  1. Next, we will install Docker with the following command:
sudo apt install docker-engine

 How to run Docker containers

El daemon Docker would already be working. Now, to run our first container, we will use the command:

sudo docker run hello-world

As we mentioned earlier, Docker containers are hosted by default on their own hub. There are hundreds or thousands of images available, so we will do a search to execute the one that interests us. For example, the search command to find an image about Linux Mint, one of the most popular Ubuntu-based distributions, would be the following:

sudo docker search "linux mint"

The previous search will show us something like the following:

docker-images

When looking for an image to run a container, we always have to use one that has the column "OK" or "Official", which means that it comes from your own project and not from just any person. In the previous list there is no official one, but there is one from Ubuntu. We will run a container using the official Ubuntu image (from the previous ones) with the following command:

sudo docker run -it ubuntu bash

The above command will download the Ubuntu image, run the container, keep it running, and give us interactive tty access within it with the Bash. We will realize that the prompt has changed to something like root @ 131a58505d2d: / #, where what is after the at is the unique ID of the container.

Using command line access we can do practically anything, like get out of the container, update the package database, update the system or install any software.

Doing cleaning

When we run a container, the Docker client has to download an image from Docker Hub. These images will be stored on our computer and will remain there even if we have stopped and eliminated the container, so all those remains are worth eliminating that we are not going to use again.

To list the images hosted on our computer, we will write the following command:

sudo docker images

This will show us all the images hosted on our computer. To eliminate them, we will write a command like the following one, where "hello-world" is the image we want to delete:

sudo docker rmi hello-world

Using the software featured in this post and its containers can be very interesting for some users. Are you one of them?

Via | linuxbsdos.com


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Beto GomHez said

    To a mortal like me, how could I install docker on my Ubuntu?

  2.   Technocybers said

    The advantage is that it does not consume physical resources but only logical ones. You can raise 20 virtual machines in a matter of two minutes, what with others it is done in hours.