In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what are the basic uses of Docker". In daily operation, I believe many people have doubts about the basic use of Docker. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the basic uses of Docker?" Next, please follow the editor to study!
1. Brief introduction and Development of containerization 1.1 introduction of Virtualization Technology
To put it simply, Docker is a virtualization technology, and there are at least three virtualization technologies.
The first is hardware virtualization, which is the underlying technical implementation.
Second: software virtualization, such as common virtual machines.
The third is the container virtualization technology that we introduce today.
Generally speaking, virtualization technology is multiple people who collaborate on one computer to work through one technology, making everyone feel as if they are working on their own computer.
In order to better understand the operating mechanism of these three virtualization technologies, let's compare the physical machine, virtual machine, and Docker system running stack.
As you can see, no matter what kind of virtualization technology it is, it is multi-layered. Among them, the blue part is the underlying implementation, and the yellow part is the implementation on the operating system and above software level. The more layers you have, the more expensive it will be to run.
System running stack analysis of physical machine:
Layer 1 Infrastructure: infrastructure layer
Layer 2 Host OS: operating system layer
Layer 3: binary / dependent libraries
Layer 4: applications
The system running stack analysis of the virtual machine:
In the underlying implementation, the virtual machine has one more layer of Hypervisor than the physical machine. This is a commonly used hardware virtualization software, which can abstract the underlying operating system into multiple underlying hardware interfaces.
In the implementation of the operating system and above software, it is divided into three parallel virtual machines, and each virtual machine running in parallel has another layer of Guest OS compared with the physical machine, that is, each virtual machine has to run its own operating system, which is a big difference from the physical machine.
Docker's system run stack analysis:
Similar to the structure of virtual machines, Docker is also divided into several "containers". But compared with the virtual machine, there is one less layer. It can be intuitively felt that the running efficiency of Docker is higher than that of virtual machines.
The Internet is often faced with a scenario: explosive traffic growth. Under such circumstances, efficiency must come first.
In view of the above three virtualization technologies, you can also compare their running efficiency in terms of their deployment and running time:
For the deployment of physical machines, the time period is probably calculated on a monthly basis. Including the construction of the computer room, the construction of the rack, the deployment of the machine, the deployment of the network, the deployment of the operating system of the machine and so on, the whole deployment cycle is very long.
Virtual machine: a virtual machine can be created in a few minutes after purchase.
Docker: Docker starts in seconds.
From the deployment, run time, we can see that the efficiency of Docker is very high.
1.2 A brief introduction to the development of containerization
Containerization technology is actually not a novel technology. As early as 1978, containerization was explored. The following figure shows a brief history of containerization technology:
1.3knowing Docker
The emergence of containers has changed the transportation industry. Docker is to the computer industry what containers are to the transportation industry.
In 2013, Docker was open source and officially released on June 9, 2014. it became popular all over the world in a short period of 15 months from Docker 0.1 to Docker 1.0. The formal announcement of embracing K8S in 2017 marks the end of the "Container Management system debate".
Why Docker can be widely accepted has the following advantages:
a. Consistency between continuous deployment and testing
Docker can keep all configurations and dependencies within the container unchanged. You can use the same container from development to product release to ensure that there are no differences or human intervention.
b. Multi-cloud platforms are compatible
It is portable and can be quickly deployed in any environment with Docker runtime. For example, AWS GCP BCE Azure aliyun supports docker, and there is no cost of migration.
c. Environmental standardization and version control
Imagine a release that destroys your entire environment due to an upgrade of a component, and Docker can easily roll back to the previous version of the image in a few minutes.
d. Isolation
Docker ensures that your application is separated from your resources. For example, relying on multiple different versions of tomcat will not cause a crash due to dependency conflicts. At the same time, Docker ensures that each container uses only the rated resources allocated to it and does not affect other containers because of one process.
e. Security.
Because the Docker container is isolated and the resources are limited. So even if one of your applications is hacked, it won't affect applications running on other Docker containers.
To sum up, the advantages of Docker can be summarized into the following three sentences:
1. One is successful, the other is successful.
Across development, testing, and deployment environments
It doesn't matter whether it's on a physical machine, a virtual machine, or a cloud.
two。 Highly integrated, highly consistent, easy to use
Easy to create and deploy, extremely efficient
Pipelined operation, continuous build release (CI/CD)
3. Combined with micro-service, the efficiency of engineering research and development is greatly improved.
App isolates from each other, decouples dependencies and facilitates flexible expansion.
There is security guarantee and no burden on access.
2. Basic use and mirroring operation of Docker container
In the first part, we have a basic understanding of Docker containers. In this section, we will give you a basic understanding of Docker container usage and mirroring operations through some practical walkthroughs and operations. Before this part is officially carried out, simple "literacy". Popularize the common terms in Docker, the environmental installation of Docker and the Docker architecture.
Common nouns
Docker image: Docker images
Docker warehouse: Docker repository
Docker container: Docker containers
Docker host: Docker host
Docker daemon: Docker daemon
Docker client: Docker client
Docker environment installation
Install Docker in the Centos system environment:
Curl-fsSL https://get.docker.com | bash-s docker
OSX system installation Docker:
Https://hub.docker.com/editions/community/docker-ce-desktop-mac
Windows system installation D ocker:
Https://hub.docker.com/editions/community/docker-ce-desktop-windows
At present, except that the Linux system can run Docker directly, other systems are based on virtual machines.
The Architecture of Docker: C _ Compact S Model
Client: a component that communicates with Docker, the client.
Docker daemon: the equivalent of a daemon, that is, the Server of docker, whose result is Containers (container)
Images: mirror image. The relationship between the mirror and the container. The running image is a container.
Registry: warehouse. The specific storage in the warehouse is an image.
2.1 Docker core concepts and usage
Docker repository Image Repository
An image repository is a place where administrative images are centrally stored. The warehouse is divided into public warehouse (DockerHub, DockerPool) and private warehouse. With the image repository, users can use it to:
A centralized repository that provides the ability to upload / download images.
Manage images in repositories, and most repositories provide retrieval and versioning capabilities.
DockerHub is a public repository provided by Docker, which can retrieve official images. In addition, there are many private registry, such as BCE, or you can build your own Docker image repository.
Docker Hub address: https://hub.docker.com
DockerFile: source code for building Docker images
Dockerfile is the source file used to generate image. The source code, like programming, has its own syntax, compilation method, and Dockerfile has its own syntax.
Here are some examples:
-FROM is generated based on the existing Docker image
For example: FROM tomcat:8.0 (meaning: use the 8.0 version of the tomcat image as our basic image, and then stack the existing image on top of it)
-COPY copy the user's files to image
For example: COPY index.jsp / usr/local/tomcat/webapps/ROOT
(COPY native file address, file address in image)
-EXPOSE provides services through this port
For example: EXPOSE 8080
-CMD starts the command that the image should run
For example: CMD ["catalina.sh", "run"]
2.2 Docker getting started command
Getting started Command 1: get help
Docker help [command] gets help with the run command.
Getting started command 2: mirror operation series commands
Docker pull [name]: [tag] pull / update an image
Docer image ls enumerates the current Docker image
Docker image rm [image ID] Delete an image
Docker build-t [name]: [tag] [dockerfile path]
Find the Dockerfile to build the image from the local path, and click on tag.
Getting started command 3: mirror run series command
Docker run-it ubuntu bash
-it: indicates an interactive terminal to run the following commands
-d: means to run the docker container to the background
Docker ps to view running containers
Docker kill [container ID] termination container
Docker run-v dor1:dir2 redis directory mount
For example: docker run-host home / user-it Ubuntu bash maps the user's home directory of host to the / user directory in the Docker instance.
Tips: frequently asked questions about mirroring
1. Where on earth is my pulled image stored?
The image is managed by Docker, and the specific path of each system is different.
The Linux system is stored in / var/lib/docker
The OSX system is stored in:
/ Users/ {YourUserName} / Library/Containers/com.docker.docker/Data
two。 What if I didn't specify the tag of the mirror?
When no mirror tag is specified in the command, latest is used as the tag by default. The way to avoid expected errors is to specify tag.
3. What if the image cannot be deleted?
Mirrors may depend on each other (layer). Add-f to force deletion.
2.3 how to Debug
1. Look at the container log:
Docker logs [container_id]
2. Inspect acquires the container / image metadata.
Docker inspect [container_id]
3. Execute interactive shell commands in the Docker instance.
Docker exec-it [container_id] bash
Docker exec- it[container _ id] s
2.4 how to build your own Docker image
1. Preparation in advance
The Dockerfile content is as follows
FROM tomcat:8.0
COPY index.jsp / usr/local/tomcat/webapps/ROOT
EXPOSE 8080
The Index.jsp content is as follows
Out. Println ("Hello World, V1")
% >
two。 Build an image
Docker build-t mytomact:1.0
Docker run-p 8080 8080-d mytomcat:1.0
Curl localhost:8080
Docker logs {Container id}
2.5 Summary of basic operation commands for image production
1. Build a Docker image
Cd node/docker
Docker build-t hub.baidubce.com/bootcamp/mynode:1.0.0
two。 Run Mirror
Docker run-d-p 8000 8080 hub.baidubce.com/bootcamp/mynode:1.0.0
Docker ps | grep mynode
Curl localhost:8000
3. View the execution log
Docker ps | grep mynode
Docker logs {container id}
3. Docker underlying core technology
Docker is a combination of technologies related to container virtualization, and its three technical pillars include: Cgroup,Namespace and AUFS. The following is a brief introduction to the three technical pillars.
3.1 Cgroup
Full name: Linux Control Group, also known as Cgroup, is a function of Linux Kernel.
Initiated and contributed by Google engineer. Finally, the kernel code is incorporated; the function is to limit the resources of a process group (including memory usage, CPU usage, disk IO, network IO, network priority, etc.)
Http://man7.org/linux/man-pages/man7/cgroups.7 .html
For example, use Cgroup to limit the amount of resources used by a process
Mkdir-p / sys/fs/cgroup/cpu/k8s_s1
Echo 50000 > / cguop/cpu/k8s_s1/cpu.cfs_quota_us
Set cpu.cfs_quota_us to 50000
Equivalent to 100000 of cpu.cfs_period_us is 50%.
Echo {PID} > / cgroup/cpu/foo/tasks
3.2 Linux Namespace
Namespace is a kernel-level method of resource isolation provided by Linux Kernel. Also known as namespaces, it is mainly used for access isolation, that is, multiple resources in the same namespace (memory, CPU, network, pid) can see each other, but not outside.
Http://man7.org/linux/man_pages/man7/namespaces.7.html
At present, there are seven types of Namespce:
For example: use Namespace to isolate the resources of a process
LSyscall. CLONE NEWPID: isolating PID
LSyscall. CLONE_NEWNET: isolate the network
3.3 AUFS
Full name: Advanced Multilayered Unification File System. A high-performance hierarchical file system that is the cornerstone of Docker image. You can mount multiple files to the same mount point. Only the first layer (the first folder level) is writable and the remaining layers are read-only. When files are added / deleted, they are converted to write operations to write to the writable layer.
When you modify a file, AUFS uses the Cow feature to modify the file in the read-only layer. No matter how much data is modified. On the first modification, the file is copied to the writable layer and then modified. The Cow feature of AUFS allows tiering to be shared among multiple containers, thereby reducing physical space footprint.
For example: use AUFS to create multiple mount points
1.Mount-t aufs-o dirs.=./fruits=tw:./vegetables=rw none./mnt
2.Echo modify > >. / mnt/tomato
At this point, the study on "what are the basic uses of Docker" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.