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

How to use linux docker Virtualization Technology

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of how to use linux docker virtualization technology, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use linux docker virtualization technology. Let's take a look at it.

1.docker Virtualization Technology introduction:

The idea of Docker comes from containers. What problems do containers solve? On a large ship, the goods can be arranged neatly. And all kinds of goods are standardized by containers, containers and containers will not affect each other. Then I don't need a ship that specializes in fruit and chemicals. As long as the goods are well packaged in a container, I can take them all away in a big ship.

Docker is a similar idea. Cloud computing is popular now, and cloud computing is like a freighter. Docker is the container.

The main problem solved: different applications may have different application environments.

Advantages of 2.docker and other virtual machine technology

Based on the container, Docker encapsulates further, from file system, network interconnection to process isolation, which greatly simplifies the creation and maintenance of the container. It makes Docker technology lighter and faster than virtual machine technology.

The following picture compares the differences between Docker and traditional virtualization. The traditional virtual machine technology is that after a set of hardware is virtualized, a complete operating system is run on it, and then the required application processes are run on the system; while the application processes in the container run directly in the host kernel, and there is no kernel in the container, and there is no hardware virtualization. Therefore, the container is lighter than the traditional virtual machine.

Compare the summary of traditional virtual machines

Characteristic Docker traditional virtual machine boot second minute hard disk generally used as MB generally GB performance close to native weaker than system support thousands of containers generally dozens of 3. Images, containers and warehouses

Docker consists of three parts: Image, Container and Repository.

The Image of Docker can be simply compared to the system disk used by a computer to install a system, including the operating system, and the necessary software. For example, an image can contain a complete centos operating system environment with samtools and bwa servers installed. Note that the mirror is read-only. This is also easy to understand, just like the system disk we burned is actually readable. We can use docker images to view the list of local images.

The Container of Docker can be simply understood as providing the hardware environment of the system. It is something that really runs the project program, consumes machine resources, and provides services. For example, we can temporarily think of the container as a Linux computer that can run directly. In that case, containers are started based on images, and each container is isolated from each other. Note that at startup, the container creates a writable layer based on the image as the top layer. We can use docker ps-a to view locally run containers.

Docker's Repository is used to store images. This is very similar to Git. We can download the image from the central warehouse or from the self-built warehouse. At the same time, we can commit the produced image locally, and then push it to the remote repository. Warehouses are divided into public warehouses and private warehouses. The largest public warehouse is the official warehouse Dock Hub. Domestic public warehouses also have many options, such as Aliyun and so on.

Docker Registry: the repository of images, such as the official Docker Hub. If we want to use images on other servers, we need a centralized service to store and distribute images, such as Docker Registry.

Registry: register the server, which is used to manage the image repository and acts as a server.

Repository: image repository, which is used to store specific docker images and plays the role of warehouse storage.

Study and use of 4.docker

Docker official website: https://www.docker.com/

Official docker image: https://hub.docker.com/

4.1 docker installation (Linux centos7)

Installation is simple. It is recommended to use root account installation: use yum automatic installation that comes with centos7.

Yum-y install dockersystemctl start docker # start docker service systemctl enable docker # set boot docker service docker version # display Docker version information docker info # display docker installation information

Ordinary users want to use docker service settings: set up non-root accounts to use docker service

Download docker image on the public database docker HUb

Search for eligible images from Docker Hub.

Docker search qiime

Pull (download) image pull from the public network docker hub

Docker pull docker.io/centos

There may be errors due to network problems. Unable to connect to the dockerhub download image. If there is nothing wrong with your network, you can download it.

Solution: use Ali Cloud docker image acceleration to improve the speed of pull:

You only need to log in to the console of the container Hub service https://cr.console.aliyun.com, use your Alipay account, set a separate password when you log in for the first time, and the accelerator help page on the left will display the acceleration address assigned to you independently.

Modify the configuration file: add the image address to vim / etc/docker/daemon.json # curly braces {}:

{"registry-mirrors": ["https://koq0g34v.mirror.aliyuncs.com"]}"

Then restart docker and take effect.

Download systemctl daemon-reload systemctl restart dockerdocker pull docker.io/centos # again, and it will be fine.

If the download of the image above is still slow, you can use a common domestic address

{"registry-mirrors": ["https://registry.docker-cn.com"]}4.3 loads the shared image docker load-I / root/docker.io-centos.tar.gz4.4 image locally to view and delete

The following is the view of the background image

REPOSITORY TAG IMAGE ID CREATED SIZEroot/sra-toolkit 2.9.2 e8a5657b4e83 About an hour ago 615 MBroot/sra-toolkit latest e8a5657b4e83 About an hour ago 615 MBdocker.io/ubuntu 18.04 72300a873c2c 2 weeks ago 64.2 MBdocker.io/centos latest 470671670cac 7 weeks ago 237 MBREPOSITORY TAG IMAGE ID CREATED SIZEroot/sra-toolkit 2.9.2 e8a5657b4e83 About an hour ago 615 MBroot/sra-toolkit latest e8a5657b4e83 About an hour ago 615 MBdocker.io/ubuntu 18.04 72300a873c2c 2 weeks ago 64.2 MBdocker.io/centos latest 470671670cac 7 weeks ago 237 MBUntagged: root/sra-toolkit:2.9.2Untagged: root/sra-toolkit:latestDeleted: sha256:e8a5657b4e838d3ce6581666752a9b428f4a1da9dd76ddac7cde90c93a93956fDeleted: sha256:97df9b1202930ab3020ee1c503db104a02b932459e32bf95a4ad0c3082d572c2Deleted: sha256:d81f279ea371ed4a05be93b3bc71726e3a38350ecaa7e19fc23c87fd61759c02Deleted: sha256:988d8a9b4254d04e208ec281aa36cbce1bef5c4e51eae806b659387a57136b0fDeleted: sha256:f778d0a1217a6a761ebad2dbff6ce5f34419d668410a4b34a986c47e3ba31b3fDeleted: sha256:6f6d62c5d1b06671066794c4640c4959b7db0773474ce92b277256759de1a14fDeleted: sha256:844f6b3eaaf0f3de53e0e72f676c455563a92d8ecce95f5edc5b03356415c2e7Deleted: sha256:9373d3173020d86eb103eac32db58836c73670e6a3440f0598324b52a2b3a542Deleted: sha256:ba7d13644b61b58c0f03abfdae3d208ef2f4819516ccfef56094927772a67e38Deleted: sha256:9a8a3c79c50a7bac2ef01a5a73e2de9a2cac2117c308ca50eac77d4b3fbd0635Deleted: sha256:6ba2b38850a58bf10195058e1952bad44c5d7240b62430ea6c553a62177d5895Deleted: sha256:fe39aa1e284cea7136534344a139d8a1acbd079054639192541478ee94f2f055Deleted: sha256:7439f6e10a4be5d6982f7f370cf5560a31cfb4cc3f69e807be22da1d02286feaDeleted: sha256:0108cbe087a1f29916bcfbefdf9fe118eef0c69ea4eea4705c89ffc4da7dd1faREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/ubuntu 18.04 72300a873c2c 2 weeks ago 64.2 MBdocker.io/centos latest 470671670cac 7 weeks ago 237 MB5. Basic usage of docker platform 5.1 run a container and load the mirror centos

After running the instance, execute the / bin/bash command in the instance

[root@omisclass ~] # docker images # View the image equals the command docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos latest 470671670cac 7 weeks ago 237 MB [root@omisclass ~] # docker run-it docker.io/centos:latest / bin/bash # Interactive run container [root@f866b20aea91 /] # exit # exit exit [root@omisclass ~] #

Common parameters of docker:

Run operation

-I runs the container in interactive mode, usually in conjunction with-t

-t reassigns a pseudo-input terminal to the container, usually used in conjunction with-I

5.2 plug-in data to docker docker run-v / root/mydata:/data-- privileged=true-- rm-it docker.io/centos:latest / bin/bash

-it: these are two parameters, one is-I: interactive operation, and the other is-t terminal. We are going to go into bash to execute some commands and see the returned results, so we need an interactive terminal.

-- rm: this parameter means that the container will be deleted after it exits. By default, exited containers are not deleted immediately in order to troubleshoot requirements, except for manual docker rm. We are just executing a random command here to see the results, and there is no need to troubleshoot and retain the results, so using-- rm can avoid wasting space.

/ bin/bash: put the command after the image name, here we want to have an interactive Shell, so we use / bin/bash.

-- privileged=true avoids the problem of mounting data directory permissions

5.3 running the docker container in the background

If your command has been written and you don't need to enter docker, you can run it directly in the background:

Docker run-d docker.io/centos:latest / bin/bash-c "while true;do echo hello world; sleep 1; done"

-d run the container in the background and return the container ID

-c followed by the command to be completed

6 Summary of commands commonly used in docker (optional)

About containers some operation commands docker ps-a #-a lists all containers container (including sleeping / exiting containers); docker kill 1629581081a1 # kills a container docker rm e085da6919af # deletes a container docker rm-f 1a63ddea6571 # forcefully deletes a container docker stop 1a63ddea6571 # closes container import and export docker export 7691a814370e | gzip > ubuntu.tar.gz # Export container zcat ubuntu.tar.gz | docker import-test/ubuntu:v1.0 # Import container is an image

Image saving and loading

Docker save docker.io/centos | gzip > rna.tar.gz # Image save docker load-I rna.tar.gz # Image load

Submit your own image to Docker Hub

Users can also use the docker push command to push their images to Docker Hub after logging in. Please replace the username in the following command with your Docker account user name.

This is the end of docker tag ubuntu:18.04 username/ubuntu:18.04docker image ls's article on "how to use linux docker Virtualization Technology". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use linux docker virtualization technology". If you want to learn more knowledge, you are welcome to follow the industry information channel.

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

Development

Wechat

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

12
Report