Introduction to docker

1. Core docker concepts

1.1 docker mirror

Doker mirroring, also known as image, is similar to virtual machine mirroring in that it can be understood as a read-only template for a polygon docker engine and also includes a file system.
Mirrors are the basis for creating containers. Through versioning and incremental file systems, the relationship between mirrors and containers can be compared to classes and objects in our object-oriented language. Mirrors are the class files we write, and containers are new objects.

1.2 docker container

A docker container is similar to a lightweight sandbox in that it uses to run and isolate applications.Containers are application running instances created from a mirror that can be started, paused, deleted, and stopped, all of which are isolated and invisible.The mirror itself is read-only, and when the container starts from the mirror, the docker creates a writable layer at the top of the mirror, leaving the mirror itself unchanged.

1.3 docker warehouse

The docker repository is just like the code repository, except that our code repository contains code, and then our docker repository mirrors the docker. The docker repository can be divided into public repositories and private repositories. Our largest docker repository is the docker hub. link
Once the user has created his or her own image, he or she can use the push command to upload it to the specified repository, so that the next time the user uses the image on another computer, he or she can pull it down directly.

1.4 Mirror, container-warehouse relationship


1. It is still understandable that the relationship between mirror and warehouse is push and pull.
2. The relationship between mirroring and containers: A mirror run can start a container, and then the container can commit to a mirror.

2. docker installation

2.1 Kernel Version

To use container technology well, the linux kernel version requires more than 3.8
Kernel version can be viewed through uname-a command

Linux hadoop101 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

2.2 Set up yum source

curl -o /etc/yum.repos.d/CentOs-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release -y
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

This is the time to use commands to view docker-ce packages that can be installed

 yum list docker-ce --show-duplicates


If you want to remove older versions of docker from your system, you can use the command

 yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2.3 Installation

yum install docker-ce


Use docker version to view versions after installation

docker version

2.4 Settings

Set boot-up self-start

systemctl enable docker

Start docker

systemctl start docker

Add Ali Cloud Mirror Source

vi /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://bsoedszv.mirror.aliyuncs.com"
  ]
}

Restart docker

systemctl restart docker

3. Run the first container

docker run hello-world

Output results:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
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/

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
First docker looks for'hello-world:latest'Mirror, and if you can't find it, go to hub and pull the mirror.
We can see from the output that there are four steps:
1.The Docker client contacted the Docker daemon. That is docker client connection docker daemon, docker is a c/s architecture
2.The Docker daemon pulled the "hello-world" image from the Docker Hub.
Docker pulls this image from docker hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
docker daemon uses this image to create a container and then run your executable.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
docker daemon returns the results to the docker client, sends them to your terminal, and then sees the output in terminal.

Tags: Docker yum Linux CentOS

Posted on Fri, 05 Jun 2020 18:37:57 -0700 by Ofro04