Docker installation and use on Centos 7

The steps below demonstrate how to install and utilize the Docker platform on a virtual server running the Centos 7 operating system.

Platform description

The Docker platform was built to allow system administrators and developers to develop, distribute, and operate applications in isolated containers.

Containerization is the process of deploying Linux software in containers.

The concept of application isolation dates back to the development of the earliest PC models and has only lately begun to be put into reality.

Containerization’s popularity has contributed to the rapid pace of software development.

So, what are the main differences between an image and a container:

  1. An image is an executable package that includes libraries, code, configuration , the runtime environment and its variables – everything that is required to open the application.
  2. A container is an instance of an image. That is, one image can contain several containers at once.

Images can be opened in read mode. Platform images are classified into two types: Linux distributions and ready-to-run enterprise software. A specific Dockerfile can be used to write the view. It’s a text file that only the Docker daemon understands. The file is created in order for the new image to be launched.

A daemon is a Docker component that is responsible for handling the arduous operations of building, distributing, and running images as soon as a command from a Docker client is received.

You can open the application on the platform in a few steps:

  1. Select the desired application.
  2. Describe it in a Dockerfile, specify the environment for running the application.
  3. Generate a common file – an image that will include a set of libraries (without a common system one) and executable files. All elements will be included in the container and will become unchanged during further work.
  4. Launch a platform that already has an image of the application used to solve the applied task.

How to install Docker

The first step is to update the local package . For this, the command is used:

sudo yum check-update

To install the most recent platform release, you must make an appeal to the official repository. You can add the required repositories and install the latest version of Docker using the command mentioned below:

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

Please keep in mind that administrators who will be running the platform other than the typical root user will need to create a new account. User entry occurs soon after the Docker group is loaded:

sudo usermod -aG docker

The full command will look like this:

sudo usermod -aG docker cloud

When the platform has done uploading to the server, launch the Docker daemon:

sudo systemctl start docker

You must ensure that the daemon starting performed well and that no error warnings were encountered:

sudo systemctl status docker

If everything is fine, the following text will appear in the window:

 docker.service - Docker Application Container Engine

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

   Active: active (running) since Thu 2018-04-26 14:06:06 MSK; 1min 56s ago

     Docs: https://docs.docker.com

 Main PID: 1601 (dockerd)

    Tasks: 16

   Memory: 40.0M

   CGroup: /system.slice/docker.service

           ├─1601 /usr/bin/dockerd

           └─1605 docker-containerd --config /var/run/docker/containerd/conta...

How to work with images

Platform commands have their own syntax, which includes the name followed by various options and arguments:

docker

Instructions on the available commands and their description can be run through a short command:

docker

All images are hosted on Docker Hub . Each user will be able to add their images to this registry. Many Linux distributions, systems, and applications create their own images on Docker Hub.

The following command determines whether the user can obtain and add photos to the registry:

docker run hello-world

If yes, the screen will display the following text:

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

9bb5a5d4561a: Pull complete

Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77

Status: Downloaded newer image for hello-world:latest

Hello from Docker!

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

To search for a specific image, use the following command syntax:

docker search

, to find an image, you would write:

docker search nginx

As a result, all images available to the user will be displayed on the screen:

[code]

NAME                                                   DESCRIPTION                                     STARS        OFFICIAL            AUTOMATED

nginx                                               Official build of Nginx.                             8341           [OK]

jwilder/nginx-proxy                                 Automated Nginx  for docker con…       1328                               [OK]

richarvey/nginx--fpm                             Container running Nginx + PHP-FPM capable of…       547                                [OK]

jrcs/letsencrypt-nginx-proxy-companion              LetsEncrypt container to use with nginx as p…       364                                [OK]

kong                                                Open-source Microservice & API Management la…       184            [OK]

webdevops/php-nginx                                 Nginx with PHP-FPM                                  102                                [OK]

[/code]

You can load the selected image using the line:

docker pull

For example, for an nginx image, the syntax would be:

docker pull nginx

The executed command will display the image loading on the screen:

Using default tag: latest

latest: Pulling from library/nginx

f2aa67a397c4: Downloading [===============>           ]   7.13MB/22.5MB

3c091c23e29d: Downloading [================>          ]  7.091MB/22.11MB

4a99993b8636: Download complete

At the end of the process, the image will be uploaded to the virtual server. To run it, use the run option:

docker run

The images option will show the images that are uploaded to the server:

docker images

The result will be a small table with a list:

[code]

REPOSITORY         TAG           IMAGE ID            CREATED             SIZE

nginx              latest        ae513a47849c        8 days ago          109MB

hello-world        latest        e38bc07ac18e        3 weeks ago         1.85kB

[/code]

How to work with containers

The following command will help to create a new container example based on the image image:

docker run --name -d

Note that the -i and -t switches are used to get interactive to the container .

You can create an example container based on nginx with the following command:

docker run --name example -d nginx

The ps option will show the containers that have been launched:

docker ps

Note that you can use the -l switch to view all existing containers.

The result will be:

CONTAINER ID      IMAGE     COMMAND                  CREATED             STATUS             PORTS       NAMES

b8f970efcc91      nginx     “nginx -g ‘daemon of…”   15 seconds ago      Up 13 seconds      80/tcp      example

Command to run a container in the background:

docker container start

For example:

docker container start example

If the container is running in the background, you can enter it using the command:

sudo docker exec -i -t /bin/

How it looks in practice:

sudo docker exec -i -t b8f970efcc91 /bin/bash
root@b8f970efcc91:/data#

The exit command will allow you to exit the container, and stop will stop its work:

docker container stop

What the full stop command looks like:

docker container stop example

To remove, use the rm option:

docker rm -f

For example:

docker rm -f example

Note that to remove open containers without having to stop them first, you should use the -f switch.

In order to run nginx through a specific port (for example, we take port 80) and make sure it works, the following command will do:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables-save

Before executing, you need to check that in the firewall settings you have opened access to port 80.

Running example container:

docker run --name example -d -p 80:80 nginx

Next, in the address bar of the browser, you need to enter the server address, specifying the port.

 

Welcome to the world of DomainRooster, where roosters (and hens) rule the roost! We're a one-stop shop for all your entrepreneurial needs, bringing together domain names and website hosting, and all the tools you need to bring your ideas to life. With our help, you'll soar to new heights and hatch great success. Think of us as your trusty sidekick, always there to lend a wing and help you navigate the sometimes-complex world of domain names and web hosting. Our team of roosters are experts in their fields and are always on hand to answer any questions and provide guidance. So why wait? Sign up today and join the ranks of the world's greatest entrepreneurs. With DomainRooster, the sky's the limit! And remember, as the saying goes, "Successful people do what unsuccessful people are not willing to do." So don't be afraid to take that leap of faith - DomainRooster is here to help you reach for the stars. Caw on!