# 1. About Docker
# Basic concepts
Docker is an open source application container engine, which allows developers to package their applications and dependency packages into a portable container, and then publish them to any popular Linux machine, or realize virtualization.
Containers are completely sandboxed, and there will be no interface between them (similar to iPhone app s). With little performance overhead, it can easily run in machines and data centers. Most importantly, they do not rely on any language, framework or system.
# Implementation mode
The goal of docker project is to achieve a lightweight operating system virtualization solution. Docker is based on Linux container (LXC), Cgroup and other technologies.
On the basis of LXC, Docker is further encapsulated, so that users do not need to care about container management, making the operation easier. The user's operation of Docker container is as simple as that of a fast and lightweight virtual machine.
# The difference between Docker and traditional virtualization
The container realizes virtualization at the operating system level and directly reuses the operating system of the local host, while the traditional way is to virtualize its own system on the basis of hardware, and then deploy relevant APP applications on the system.
-
Traditional virtualization solutions:
-
Docker virtualization scheme:
Docker virtualization has three concepts to understand: image, container and warehouse.
-
Image: the image of docker is actually a template, similar to our common ISO image. It is a template.
-
Container: an application or system created using an image, which we call a container.
-
Warehouse: a warehouse is a place where images are stored. It is divided into two forms: Public warehouse and Private warehouse.
# Docker virtualization features
-
Fast operation start
The performance of runtime can be greatly improved. Management operations (start, stop, start, restart, etc.) are in seconds or milliseconds.
-
Lightweight virtualization
You will have enough "operating systems" to add or reduce images. Hundreds of Containers can be deployed on one server. But with traditional virtualization, it's good for you to virtualize 20 virtual machines.
-
Open source free
Open source, free, low cost. Supported and driven by the modern Linux kernel. Lightweight containers can certainly open more "containers" on a physical machine, which is destined to be cheaper than VMs.
# 2. Preliminary preparations for installing Docker
-
Step 0: in the development environment, we usually turn off the firewall
systemctl status firewalld # View firewall status systemctl stop firewalld # Close, effective only for the current systemctl disable firewalld # Boot disable
Copied! -
Step 1: View kernel version
Docker officially requires the Linux kernel version to be at least 3.8 or above, and it is recommended to be above 3.10. The kernel version can be viewed with the following command:
uname -r
Copied!The kernel version of CentOS 7 meets its requirements.
-
Step 2: uninstall the old version
The older docker version is called docker or docker-engine . If you have installed these programs, uninstall them and their related dependencies.
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
Copied! -
Step 3: prepare for configuring docker software source
yum install -y \ yum-utils \ device-mapper-persistent-data \ lvm2
Copied! -
Step 4: add docker software source
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
Copied!Considering that downloading docker CE from docker's official warehouse is sometimes slow, you can use the following command to change the download website to Huawei's image server:
sudo sed -i \ 's+download.docker.com+repo.huaweicloud.com/docker-ce+' \ /etc/yum.repos.d/docker-ce.repo
Copied!
What have we done so far?
There is actually a docker installation package in the default Yum software source of CentOS. If you do it directly yum install docker It is also feasible.
However, considering that different users have different needs for different versions of docker (some pursue the latest and others pursue stability), docker officials have specially provided a warehouse / website to provide the download of multiple versions of docker.
Therefore, we must inform yum of the existence of such a warehouse, and ask yum to download the version of docker specified by us from this warehouse in the future. Instead of the default warehouse.
-
Step 5: validation
View all docker versions in all warehouses
yum list docker-ce --showduplicates | sort -r
Copied!
# 3. Install docker and verify
-
Download from the network warehouse and install the latest version
yum install -y docker-ce
Copied!Or specify a specific version. For example:
yum install -y docker-ce-18.06.3.ce-3.el7
Copied!The following questions will appear during installation:
from https://download.docker.com/linux/centos/gpg retrieve key Import GPG key 0x621E9F35: user ID : "Docker Release (CE rpm) <[email protected]>" fingerprint : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35 come from : https://download.docker.com/linux/centos/gpg Continue?[y/N]:
Copied!input y Press enter to continue installation.
Eventually:
complete!
Copied! -
Start Docker and add it to startup
# systemctl start docker systemctl enable docker --now systemctl status docker
Copied!Similar results will appear as follows:
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
Copied! -
Verify that the installation was successful
(there are two parts: client and service, which means that the installation and startup of docker are successful)
input docker version Command, the following will appear:
Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:15:20 2018 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:54 2018 OS/Arch: linux/amd64 Experimental: false
Copied! -
Verify the connection to the docker hub central image warehouse
input docker search -f is-official=true mysql Command, the following results will appear:
NAME DESCRIPTION STARS OFFICIAL ... mysql MySQL is a widely used, open-source relation... 8819 [OK] ... mariadb MariaDB is a community-developed fork of MyS... 3102 [OK] ... percona Percona Server is a fork of the MySQL relati... 459 [OK] ...
Copied!
# 4. Configure domestic image
Since the central image warehouse of docker hub is located abroad, sometimes it is very moving for us to connect to docker hub and download images from it. Therefore, we need to configure the domestic image website to mirror files from home.
TIP
The domestic image is essentially a cache / backup of the docker hub central warehouse in China.
Edit the relevant configuration file through the vi command:
vi /etc/docker/daemon.jsonCopied!
If the file exists, its contents will be cleared; If the file does not exist, (after opening the file, its content is blank), save and exit after editing, that is, create.
Enter the following:
{ "registry-mirrors": [ "https://registry.docker-cn.com", "https://docker.mirrors.ustc.edu.cn" ] }Copied!
The configuration file is configured with two images, one is the official image of docker in China, and the other is an image maintained by China University of science and technology.
Restart docker service:
systemctl restart dockerCopied!
View modification results:
docker infoCopied!
There will be the following:
... Registry Mirrors: https://registry.docker-cn.com/ https://docker.mirrors.ustc.edu.cn/ ...Copied!
# 5. Import the existing image file
Considering the inconvenience of networking in some scenarios, docker provides the function of packaging and exporting downloaded images and importing them elsewhere.
To export an existing image, use the following command:
docker save <repository>:<tag> -o <repository>.tarCopied!
For example:
docker save mysql:8.0.16 -o mysql-8.0.16.tarCopied!
To import an image, use the following command:
docker load -i <repository>.tarCopied!
For example:
docker load -i mysql-8.0.16.tar