In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
I. Overview of Docker
Docker is an open source tool that runs in a Linux container and is a lightweight virtual machine. Its design purpose: Build,Ship and Run Any App,Anywhere, that is, through the corresponding component packaging, release, deployment, operation and other life cycle management, to achieve the component level of "once encapsulated, run everywhere" purpose. The components here can be either an application, a set of services, or even a complete operating system.
Three core concepts of Docker: images, containers, repositories, installation of Docker, and specific operations around images and containers.
Second, compared with the advantages of traditional virtual machine Dokcer
1. The Docker container is very fast, and start and stop can be implemented in seconds, much faster than traditional virtual machines.
2. The problem solved by the core of Docker is to use containers to achieve functions similar to VM, so as to provide users with more computing resources with more saved hardware resources, so Docker containers basically do not consume additional system resources in addition to running the applications in it, thus ensuring performance while reducing system overhead, making it possible to run thousands of Docker containers on one host at the same time.
3. Docker is easy to operate, and it can also support flexible automatic creation and deployment through Dockerfile configuration files.
III. The architecture of Docker and traditional virtual machines
The reason why Docke has many advantages is inseparable from the characteristics of operating system virtualization. Traditional virtual machines need to have additional hypervisors.
IV. Core concept and installation of Docker
1. Mirror image (Image)
Docker image is the basis for creating containers, similar to virtual machine snapshots, which can be understood as a read-only template for Docker container engine, such as: an image can be a complete CentOS operating system environment and become a CentOS image; it can be an application with MySQL installed, called a MySQL image, and so on.
Docker provides a simple mechanism to create and update existing images, and users can download existing application images from the Internet to use them directly.
2. Container (container)
The container for Docker is a running real column created from the image, which can be started, stopped, and deleted. Each container created is isolated and complementary to each other, which can ensure the security of the platform. You can also think of containers as a simple version of the Linux environment, where Docker uses containers to run and isolate applications.
3. Warehouse (Repository)
Docker repository is used to store images centrally. After creating your own image, you can use the push command to upload it to public repository (Pulic) or private repository (Private), so that the next time you want to use the image on another machine, you just need to pull it from the repository.
The Warehouse Registration Server (Registry) is the place where the warehouse is stored, which contains multiple repositories, each of which stores a certain type of image and uses different tags to distinguish them. At present, the largest public repository is DockerHUb, which stores a large number of images for users to download and use.
4. Installation of Docker
Vi / etc/yum.repos.d/CentOS-Base.repo / / configure the yum source
Add the following to the last line:
[docker-repo]
Name=Docker Repository
Baseurl= https://yum.dockerproject.org/repo/main/centos/7/
Enabled=1
Gpgcheck=1
Gpgkey= https://yum.dockerproject.org/gpg
Yum install-y docker-engine / / install Docker engine systemctl enable docker / / Boot self-boot systemctl start docker / / start docker V, Docker image operation
The corresponding image needs to exist locally before Docker runs the container. If there is no local image, Docker will try to download it from the default image repository https://hub.docker.com, which is a public repository officially maintained by Docker and can meet most of the needs of users. Users can also use custom image repositories through configuration.
1. Search for images (queried from Docker Hub by default)
There are three ways to obtain an image:
1) download the image (download from Docker Hub by default)
2) convert the container to an image
3) create an image (generate an image through dockerfile)
Docker search httpd / / find all httpd related images
2. Download the image (download from Docker Hub by default)
Docker pull httpd / / pull apache image
3. View the image
Docker images / / View the list of local images
Description of each option:
REPOSITORY: indicates the warehouse source of the image
TAG: the label that represents the image
IMAGE ID: indicates the ID of the mirror
CREATED: indicates the time when the image was created
SIZE: indicates the image size
Docker tag httpd apache:test / / add a new tag to the image
4. Delete the image
Docker rmi repository name: label docker rmi-f image ID / / permanently delete image docker rmi-f $(docker images | grep "none" | awk "{print\ $3}") / / Delete unused images
5. Export and import images
Docker save-o export file name exported image docker save-o httpd01 httpd / / export image
Export of docker load File name / / Container
Cat file name | docker import-generated image name: label / / Import the container file as an image
4. Deletion of containers
Docker ps-adocker rm container ID / / Delete containers. Cannot delete running containers docker rm-f d4e863a654aa / / forcibly delete running containers. It is not recommended. Docker container prune / / Delete all stopped containers docker rm $(docker ps-qf status=exited) / / Delete containers in the specified state 7. Docker warehouse
Docker login / / Log in to the shared warehouse and log in through the registered account
VIII. Docker resource control (optimization)
1. Limit the rate of use of CPU
In Docker, the usage of CPU can be limited by the-- cpu-quota option, and the percentage of CPU is in 1000.
Docker run-the usage of cpu-quota 20000 image name / / CPU is limited to 20%
2. Share CPU proportionally with multi-task
When running by multiple container tasks, it is difficult to calculate the CPU utilization. In order to make the container make rational use of CPU resources, you can use the-- cpu-shares option to set CPU to share CPU resources proportionally. This way can also achieve dynamic adjustment of CPU utilization.
The following three containers A, B, and C are implemented, and the ratio of CPU resources consumed is listed as 1:1:2
Docker run-- cpu-shares 1024 image name / / corresponding container Adocker run-- cpu-shares 1024 image name / / corresponding container Bdocker run-- cpu-shares 2048 image name / / corresponding container C
3. Limit the use of CPU kernel
You can use the-- cpuset-cpus option in Docker to make some programs exclusive to the CPU kernel to improve their processing speed, and the corresponding Cgroup configuration file is / sys/fs/cgroup/cpuset/docker/ container number / cpuset.cpus. Option is followed directly by parameters 0, 1, 2. Represents the first kernel, the second kernel, and the third kernel, the same as the CPU number (processer) in / proc/cpuinfo.
If the server has 16 cores, then the CPU number is 0-15, which binds the container to the 1st-4th kernels for use.
Docker run-- cpuset-cpus 0meme 1pr 2je 3 image name
4. Restrictions on memory usage
In Docker, you can use the docker run-m command to limit the memory usage of the container, and the corresponding Cgroup configuration file is / sys/fs/cgroup/memory/memory.limit_in_bytes. But it's important to note that once the container Cgroup exceeds the limit, the Linux kernel will try to reclaim that memory, and if you still can't control the memory usage within the limit, the process will kill.
Docker run-m 512m image name / / limit the memory of the container to 512m
5. Restrictions on blkio
If the container is mixed deployed on one server, there will be several programs writing disk data at the same time, so you can use the-- device-write-iops option to limit the iops written, and the-- device-read-bps option to limit the iops read. But this approach is only for blkio-restricted devices (device), not partitions. The corresponding Cgroup writes the configuration file / sys/fs/cgroup/blkio/docker/ container ID/blkio.throttle.write_iops_device.
Docker run-- device-write-bps / dev/sda1:1mb image name / / limit / write iops of / dev/sdb1 is 1MB
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.