Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker series: lecture 1. Introduction and installation of Docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What is Docker?

The English translation of Docker means "porter". What he carries is that we often say that the container Container,Container contains any type of App. Our developers can turn App into a standardized, portable, self-managed component through Docker, and we can develop, debug and run in any mainstream operating system.

What is the difference between Docker and a virtual machine?

Conceptually, Docker is similar to our traditional virtual machine, except that it is lighter and more convenient. The main differences between Docker and virtual machine are as follows:

Virtualization technology relies on physical CPU and memory, which is hardware-level, while our Docker is built at the operating system level, using the containerization technology of the operating system, so Docker can also run on virtual machines. We know that the system in the virtual machine is what we often call the operating system image, which is more complex; while Docker is relatively lightweight, we can deploy an independent Redis with Docker, which is similar to installing a Redis application in the virtual machine, but the application we deploy with Docker is completely isolated. We all know that traditional virtualization technology saves state through snapshots, while Docker introduces a mechanism similar to source code management to record the historical versions of snapshots of containers one by one, and the switching cost is very low. Traditional virtualization technologies are very complex when building systems; Docker can build the entire container through a simple Dockerfile file, and more importantly, Dockerfile can be written manually, so that application developers can define the application environment and dependencies by publishing Dockerfile, which is very beneficial for continuous delivery. Why use containers?

What does an application container look like? a finished application container looks like a virtual machine with a specific set of applications. For example, if I want to use Redis, I can find a container with Redis, and then run it, and I can use it directly.

So why can't you just install a Redis? It is certainly feasible, but sometimes all kinds of errors may be reported during installation, depending on everyone's computer. In case your machine is poisoned, your computer crashes, and all your services need to be reinstalled. But with Docker or container, you have a virtual machine that can run. As long as you can run the container, the configuration of Redis will be saved. And if you want to change the computer, no problem, it's very simple, just "bring" the container and you can use the service inside the container.

Docker architecture

Docker uses the architecture of the Docker S (client / server) architecture, the Docker client communicates with the Docker daemon, and the Docker daemon is responsible for building, running, and distributing the Docker container. The Docker client and daemon can run on the same system, or you can connect the Docker client to the remote Docker daemon. Docker clients and daemons use REST API to communicate over UNIX sockets or network interfaces.

Docker Damon:dockerd, which is used to listen for Docker API requests and manage Docker objects such as mirrors, containers, networks, and Volume. Docker Client:docker,docker client is the main way for us to interact with Docker. For example, we can run a container through the docker run command, and then our client will send the command to the Dockerd above and let him do the real thing. Docker Registry: a repository for storing Docker images. Docker Hub is a public repository provided by Docker, and Docker also looks for images from Docker Hub by default. Of course, you can easily run a private repository. When we use the docker pull or docker run command, we pull images from our configured Docker image repository, and when we use the docker push command, we push the constructed images to the corresponding image repository. Images: an image is a read-only template with instructions for creating a Docker container. Generally speaking, an image is based on some other basic image with some additional customization features. For example, you can build a Centos-based image, and then install a Nginx server on top of the basic image, so that you can form our own image. Containers: a container is a runnable instance of a mirror. You can use Docker REST API or CLI to manipulate the container. The container is essentially a process, but unlike a process executed directly in the host, the container process runs in its own independent namespace. So the container can have its own root file system, its own network configuration, its own process space, and even its own user ID space. Processes in the container run in an isolated environment and are used as if they were operating on a system independent of the host. This feature makes container-encapsulated applications more secure than running directly in the host. Underlying technical support: Namespaces (isolation), CGroups (resource restriction), UnionFS (layering of images and containers) the-underlying-technology Docker underlying architecture analysis Docker installation

Go directly to the official documentation and select the appropriate platform to install. For example, if we want to install Docker on the centos system, go to the address https://docs.docker.com/install/linux/docker-ce/centos/ and follow the prompts to install it.

1. Install dependent software packages:

$sudo yum install-y yum-utils device-mapper-persistent-data lvm2

2. Add a software repository. We use the stable version of Docker here and execute the following command to add the address of the yum repository:

$sudo yum-config-manager\-add-repo\ https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo# official source # $sudo yum-config-manager\ #-add-repo\ # https://download.docker.com/linux/centos/docker-ce.repo

3. Then install it directly:

$sudo yum install docker-ce

4. If you want to install the specified version, you can use yum list to list the available versions:

$yum list docker-ce--showduplicates | sort-rdocker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable

5. For example, you can install the 18.03.0.ce version here:

$sudo yum install docker-ce-18.03.0.ce

6. It is also very simple to start Docker:

$sudo systemctl enable docker$ sudo systemctl start docker

7. Another installation method is to download the specified software package directly and install it directly. Go to https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ to find the appropriate .rpm package to download, and then install it:

$sudo yum install / path/to/package.rpmDocker accelerator

It is sometimes difficult to pull an image from Docker Hub in China, so you can configure the image accelerator. Docker officials and many domestic cloud service providers provide domestic accelerator services, such as:

China registry mirror https://registry.docker-cn.com officially provided by Docker

Qiniuyun accelerator https://reg-mirror.qiniu.com/

After configuring an accelerator address, if you find that the mirror cannot be pulled, please switch to another accelerator address. All the major cloud service providers in China provide Docker image acceleration service. It is recommended to select the corresponding image acceleration service according to the cloud platform running Docker.

For systems that use systemd, write the following in / etc/docker/daemon.json (create a new file if it does not exist)

{"registry-mirrors": ["https://registry.docker-cn.com"]}

Note: make sure that the file conforms to the json specification, otherwise Docker will not start.

Restart the service.

$sudo systemctl daemon-reload$ sudo systemctl restart docker tests whether Docker is installed correctly $docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldca4f61b1923c: Pull completeDigest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905cStatus: Downloaded newer image for hello-world:latestHello from docking 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 bashShare images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/For more examples and ideas, visit: https://docs.docker.com/engine/userguide/

If the above information can be output normally, the installation is successful.

Add kernel parameters

By default, if you use Docker CE in CentOS, you will see the following warning messages:

WARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is disabled

Please add kernel configuration parameters to enable these features.

$sudo tee-a / etc/sysctl.conf

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report