Docker container technology learning (1)

Install and deploy Docker

What is Docker

Docker is developed based on the Golang language launched by Google. It is based on the Cgroups, NameSpace, Union FS and other technologies of the Linux kernel to encapsulate and isolate processes. It is a virtualization technology at the operating system level.

Because the isolated process is independent of the host and other isolated processes, it is also called a container.

The original Docker was based on LXC. Later, LXC was removed and the self-developed Libcontainer was used.

Doc is defined as an open source container engine that can easily manage containers, such as packaging and encapsulating images, and introducing Docker Registry for unified image management.

Docker can be used to achieve consistent deployment of development, testing, and production environments, greatly reducing operation and maintenance costs.

The difference between containers and virtual machines

Traditional virtual machine technology

A virtual machine virtualizes a set of hardware and runs a complete operating system on it. For example, we use KVM, specify the system image, then install the system and run the application in the system.
When KVM creates a virtual machine, it specifies fewer resources such as CPU, memory, hard disk, etc., and the performance of the virtual machine is lower.

Docker container technology

Container applications run directly on the host kernel. Containers share an operating system kernel, which isolates the application process from other parts of the system. The container does not have its own kernel, and the hardware is not virtualized. Therefore, the container is different from the virtual machine. More lightweight.

Benefits of Containers vs. KVM

  • Containers can provide host performance, while KVM virtual machines allocate host hardware resources and have weaker performance.
  • The same configured host can enable up to 10 virtual machines and 100+ containers.
  • The KVM virtual machine takes a long time to start, and it only takes 1 second to start a container.
  • KVM requires virtualization support from the hardware CPU, but containers do not
The core component of docker
  • Image mirror, build a container (that is, the environment required for application running, packaged as an image file)
  • Container, container (the application runs in the container)
  • The image warehouse (dockerhub) functions like GitHub, saving image files and providing uploading and downloading of images.
  • Dockerfile writes the operation of deploying your project into a deployment script, which is the dockerfile, and the script can also build an image file.
The process of creating a container
  • Get the image and pull it from the image warehouse
  • Create containers using images
  • Allocate a file system, mount a read-write layer, and add mirroring to the read-write layer
  • Assign a network/bridge interface and create a network interface to allow the container to communicate with the host.
  • Container gets IP address
  • Execute container command
  • Feedback container startup results

Install Docker

For detailed installation instructions of Docker, please refer to its official documentation: Docker official installation documentation link

I use Mac and cloud server CentOS systems, so I need to deploy and use docker on both systems.

1. Deploy docker on CentOS

According to the official documentation, the first step is to uninstall the old version. If docker is not installed on the system, you can skip this step.

Before installing Docker Engine on a new host for the first time, you need to set up a Docker repository. Docker can then be installed and updated from the repository.

1. Set up a mirror warehouse

Install the yum-utils package (it provides the yum-config-manager utility) and set up the repository.

 sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
2. Install Docker Engine

(1) Install the latest versions of Docker Engine, containerd, and Docker Compose, or perform the next step to install a specific version:

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

(2) To install a specific version of Docker Engine, list the available versions in the repository, then select and install:

a. List and sort the versions available in the repository. The following example sorts the version number from high to low, and then truncates: ## Function shortcut keys:

yum list docker-ce --showduplicates | sort -r

The list returned depends on which repositories are enabled, and is specific to your version of CentOS (indicated by the .el7 suffix in this example).

b. Install a specific version by the fully qualified name of the package, which is the package name (docker-ce) plus the version string (second column), starting with the first colon (:) and ending with the first hyphen (-) , separated by a hyphen (-). For example, docker-ce-18.09.1.

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin

For example:

yum -y install docker-ce-18.03.1.ce
3. Start Docker
systemctl start docker
4. Verify the installation is successful
docker version
5. Uninstall
# 1. 卸载依赖
yum	 remove docker-ce docker-ce-cli containerd.io
# 2. 删除资源(/var/lib/docker  docker的默认工作路径)
rm -rf /var/lib/docker

2. Install and deploy Docker on Mac

Since the package management tool Homebrew was installed before, we use the brew command to install it:

brew install --cask --appdir=/Applications docker

After the installation is successful, run the command on the terminal to check the Docker version.

docker --version

Guess you like

Origin blog.csdn.net/h21396577548/article/details/127923923