Docker entry to actual combat (1)

Docker-related concepts

If you want to really understand Docker, you have to start with the development of virtualization technology. It is generally believed that virtualization technology has gone through the era of physical machines and virtual machines, and has now entered the era of containerization. It can be said that Docker is the inevitable result of the continuous development of virtualization technology. So, what is a container? What's the difference between containers and virtual machines? What is the relationship between Docker and containers? After understanding these questions, the concept of Docker is clear.

1.1 Virtual machines and containers

With the help of software such as VMWare, multiple virtual machines can be created on one computer. Each virtual machine has an independent operating system and can run programs independently. Although this avatar technique has a high degree of isolation (operating system level) and is easy to use (similar to a physical machine), it also has the obvious disadvantages of taking up a lot of storage resources (GB level) and slow startup speed (minute level).

Compared with a virtual machine, a container (Container) is a lightweight virtualization technology. It virtualizes the simplest operating environment (similar to a sandbox) rather than an operating system. It starts up quickly (seconds) and takes up storage space. Less resources (KB level or MB level), the isolation between containers is at the process level. Thousands of containers can run on one computer, which is the crushing advantage of container technology over virtual machines.

1.2 Containers, images and Docker

Docker is an open source application container engine that can create containers and programs based on containers. Docker allows developers to package their applications and dependencies into a lightweight, portable container, and then publish it to any popular Linux machine, and it can also be virtualized.

It sounds simple, but between Docker and containers, there is a concept of mirroring, which confuses beginners. In essence, a Docker image is a special file system that provides programs, libraries, resources, configurations, and other files needed for the container to run. A Docker image is similar to a py file that requires Docker's runtime (similar to the Python interpreter) to run. When the image is run, an instance of the image is created, and an instance is a container.

1.3 Docker and k8s

As a container engine, Docker provides open standards for containerized applications, allowing developers to manage infrastructure in the same way as applications, enabling rapid delivery, testing, and deployment of code. With the extensive use of containers, the problem of how to coordinate, schedule, and manage containers has arisen, and Docker's container orchestration came into being.

k8s is a container orchestration engine open sourced by Google. It supports automated deployment, large-scale scalability, and application container management. It is an open source and is used to manage containerized applications on multiple hosts in the cloud platform. The goal of k8s is To make deploying containerized applications simple and efficient, k8s provides a mechanism for application deployment, planning, updating, and maintenance.

Both Docker and k8sr use containerd (containerization standard) as the runtime, so images created using Docker can be used in k8s without any obstacles.

Docker installation

2.1 Install in ubuntu

Installing Docker in the linux system is very simple, and the official provides us with a one-click installation script. This method also works on distributions like Debian or CentOS.

curl -sSL https://get.daocloud.io/docker | sh

If there is a timeout during the installation process, don't be discouraged, try a few more times, and it will always succeed. After the installation is complete, Docker can only be used by the root user. You can use the following command to cancel the permission restriction:

sudo gpasswd -a <你的用户名> docker

Then, restart the docker service:

sudo service docker restart

Finally, close the current command line and reopen the new command line. By the way, if you install under CentOS, there may be a bunch of errors similar to the following:

问题 1: problem with installed package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64
  - package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
  - package podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
  - package podman-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - cannot install the best candidate for the job
  - package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-65.rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered out by modular filtering
 问题 2: package podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
  - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package docker-ce-3:20.10.7-3.el8.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed
  - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package podman-catatonit-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires podman = 3.0.1-6.module_el8.4.0+781+acf4c33b, but none of the providers can be installed
  - problem with installed package podman-catatonit-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64
  - package podman-catatonit-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires podman = 3.0.1-7.module_el8.4.0+830+8027e1c4, but none of the providers can be installed
  - package podman-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
  - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
  - cannot install the best candidate for the job
  - package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-65.rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered out by modular filtering
  - package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered out by modular filtering
  - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
  - package podman-catatonit-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires podman = 2.0.5-5.module_el8.3.0+512+b3b58dca, but none of the providers can be installed
  - package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed

This is caused by the conflict between docker and Podman, you need to uninstall Podman first:

yum erase podman buildah

2.2 Install in Win10

The operation of Docker depends on the linux environment. The official Docker Desktop for Windows is provided, but it needs to install Hyper-V. Hyper-V is a virtual machine developed by Microsoft, similar to VMWare or VirtualBox, and it is only applicable to Windows 10. Once this virtual machine is enabled, QEMU, VirtualBox or VMWare Workstation 15 and below will not work! If you must use another virtual machine on your computer (such as an emulator to develop Android applications), please do not use Hyper-V! My computer is Win10 Home Edition, and hyper-v cannot be installed directly. The following command needs to be saved in a cmd file:

pushd "%~dp0"

dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt

for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"

del hyper-v.txt

Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL

Then right click on the cmd file and select run as administrator. After the execution is complete, it will restart, and the installation will be carried out during the restart process.

2.3 Hello world

With the docker service started, run the following command:

docker run ubuntu:20.04 /bin/echo "Hello world"

The meaning of this command is:

  • docker run: run the docker image command
  • ubuntu:20.04: The image name is ubuntu version number is 20.04
  • /bin/echo "Hello world": running parameters, the meaning of the parameters of this image is that the echo command running the image displays hello world

When running for the first time, because there is no ubuntu:20.04 image locally, docker will automatically download it from the image server. The download process may need to be tried several times, as long as it succeeds once, it will no longer need to be downloaded in future executions. Docker official also provides a hello-world image, which can be run directly:

docker run hello-world

This command omits the image version and running parameters, and docker uses latest as the version, that is, the latest version. From the example of hello world, you can also experience that the running of the docker instance is very fast.

Guess you like

Origin blog.csdn.net/qq_28165595/article/details/131877103