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/02 Report--
Blog structure Docker Mirror Operation Docker Container Operation Docker Resource Control Docker Core concept
One. What is Docker?
(1) Docker is an open source tool for running applications in a Linux container and is a lightweight "virtual machine"
Logo is designed as a blue whale, whales can be thought of as hosts, and the containers above can be understood as isolated containers, each containing its own application.
(2) the difference between Docker and virtual machine
As a lightweight way of virtualization, Docker has significant advantages over traditional virtual machines.
The reason why Docker has many advantages is inseparable from the characteristics of operating system virtualization. Traditional virtual machines require additional hypervisors and virtual operating system layers, while Docker containers are virtualized directly above the operating system level
As shown in the figure:
(3) usage scenarios of Docker
Now developers need to be able to easily create applications that run on cloud platforms, break away from the underlying hardware, and have access to these resources anytime and anywhere, which is what Docker has to offer. Docker's container technology can easily create a lightweight, portable, self-sufficient container for any application on a single host. Packaging applications through this container means simplifying the trivial repetitive work of redeploying and debugging, and greatly improving productivity.
II. The core concept and installation of Docker
(1) Image
The mage of Docker is the basis for creating containers, similar to snapshots of virtual machines
It can be understood as a read-only template for the Docker container engine. For example, an image can be a complete CentOS operating system environment, called a CentOS
Image; it can be an application with MySQL installed, called a MySQL image, and so on.
(2) containers
The container (Container) of Dooker is a running instance created from an image. It can be started, stopped, and deleted. Each container created is a platform that is isolated from each other, invisible to each other, and ensures security. Think of the container as a simple version of the Linux ring
Docker uses containers to run and isolate applications.
(3) Warehouse
Docker Repository is a place where images are stored centrally. After creating your own image, you can use the push command to upload it to a public repository (Public) or a 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.
(4) install Docker
If the host has a network, it can be installed directly.
Configure yum
[root@localhost ~] # rm-rf / etc/yum.repos.d/* [root@localhost ~] # vim / etc/yum.repos.d/a.repo [aaa] name=asdbaseurl= file:///mediagpgcheck=0[root@localhost ~] # mount / dev/cdrom / media/ [root@localhost ~] # yum-y install docker
When the installation is complete, you can start Docker and set it to boot.
[root@localhost ~] # systemctl start docker [root@localhost ~] # systemctl enable dockerCreated symlink from / etc/systemd/system/multi-user.target.wants/docker.service to / usr/lib/systemd/system/docker.service. [root@localhost ~] # docker version / / View Docker version Client: Version: 1.13.1 API version: 1.26 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64 Go version: Go1.9.4 Git commit: 8633870 Built: Fri Sep 28 19:45:08 2018 OS/Arch: linux/amd64Server: Version: 1.13.1 API version: 1.26 (minimum version 1.12) Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64 Go version: go1.9.4 Git commit: 8633870 Built: 1.13.1 Built: Fri Sep 28 19:45:08 2018 OS/Arch: linux/amd64 Experimental: false
Divided into server and client
III. Docker mirror operation
(1) search for images (provided the computer has a network)
[root@localhost ~] # docker search dhcpINDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATEDdocker.io docker.io/networkboot/dhcpd Suitable for running a DHCP server for you... 43 [OK] docker.io docker.io/joebiellik/dhcpd DHCP server running on Alpine Linux 15 [OK] docker.io docker.io/gns3/dhcp A DHCP container for GNS3 using dnsmasq 3 [OK] docker.io docker.io/instantlinux/dhcpd-dns-pxe Serve DNS DHCP and TFTP from a small Alpi... 2 [OK] docker.io docker.io/ictu/dhcpd-tftpd dhcpd tftpd container 1 [OK] docker.io docker.io/marcelwiget/dhcptester Simple dhcp client simula
(2) obtain the image
[root@localhost] # docker pull docker.io/network/dhcpd / / download the dhcp at the beginning of the above
Another way is to insert the downloaded dhcp.
Make the CD and insert it into the host
[root@localhost ~] # mount / dev/cdrom / media/ [root@localhost ~] # cd / media/ [root@localhost media] # lsdhcp [root@localhost media] # cp dhcp / [root@localhost media] # [root@localhost /] # docker load
< dhcpfccbfa2912f0: Loading layer 116.9 MB/116.9 MBe1a9a6284d0d: Loading layer 15.87 kB/15.87 kBac7299292f8b: Loading layer 14.85 kB/14.85 kBa5e66470b281: Loading layer 5.632 kB/5.632 kBa8de0e025d94: Loading layer 3.072 kB/3.072 kBe2e29955c5aa: Loading layer 12.7 MB/12.7 MB12e14fab4dd4: Loading layer 49.15 kB/49.15 kB47bdfd3bbf39: Loading layer 4.096 kB/4.096 kBLoaded image: docker.io/networkboot/dhcpd:latest 将镜像下载到本地 (3)查看镜像信息 [root@localhost /]# docker imagesREPOSITORY TAG IMAGE ID //镜像ID CREATED SIZEdocker.io/networkboot/dhcpd latest 6f98b6b9b486 19 months ago 125 MBREPOSITORY: 镜像属于的仓库。TAG: 镜像的标签信息,标记同一个仓库中的不同镜像。IMAGE ID: 镜像的唯一ID号,唯一标识了该镜像。CREATED: 镜像创建时间。CREATED: 镜像创建时间。 [root@localhost /]# docker inspect 6f98b6b9b486 \查看镜像ID详细信息 镜像的详细信息中包括创建时间、系统版本.主机名.域名.用户.卷.标签.操作系统.设备ID等各种信息。 [root@localhost /]# docker tag docker.io/networkboot/dhcpd dhcp:dhcp 第一个dhcp:名称第二个dhcp:标签 (4)删除镜像 [root@localhost /]# docker rmi dhcp:dhcpUntagged: dhcp:dhcp 四.Docker容器操作 容器是Docker的另一一个核心概念,简单来说,容器是镜像的一个运行实例,是独立运行的一个或一组应用及它们所必需的运行环境,包括文件系统、系统类库. shell 环境等。镜像是只读模板,而容器会给这个只读模板一个额外的可写层 (1)容器的创建与启动 [root@localhost /]# docker create -it docker.io/networkboot/dhcpd /bin/bashe392026ddd186d01cbd3306acae15f2f197dc9874a84ea241d347c7fe20a0946 常用选项: -i表示让容器的输入保持打开: -t表示让Docker分配一个伪终端。 [root@localhost /]# docker ps -a \\查看所有容器运行状态CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe392026ddd18 docker.io/networkboot/dhcpd "/entrypoint.sh /b..." About a minute ago Created elegant_goldwasser 输出信息显示容器的ID号.加载的镜像.运行的程序.创建时间、目前所处的状态、端口映射.容器名称等。其中状态-栏为Created表示当前的容器是新创建的并处于停止状态。 [root@localhost /]# docker start e392026ddd18 \\启动容器 ,上面的IDe392026ddd18 容器启动后,可以看到容器状态一栏已经变为UP,表示容器已经处于启动状态。 (2)容器的运行与终止 [root@localhost /]# docker stop 容器的ID号 (3)容器的进入 [root@localhost /]# docker exec -it e392026ddd18 /bin/bashroot@e392026ddd18:/# 用户可以通过所创建的终端来输入命令,通过exit命令退出容器. root@e392026ddd18:/# lsbin core entrypoint.sh home lib64 mnt proc run srv tmp varboot dev etc lib media opt root sbin sys usrroot@e392026ddd18:/# exitexit (4)容器的导出导入 容器是最小化,导致一些命令不能使用,所以就要从容器里面导出到本地来设置,设置完再导入进容器就可以。 导出命令如下: [root@localhost /]# docker export e392026ddd18>/ etc/dhcp/dhcpd.conf
The random number is the ID number of the container
Export the dhcp main configuration file to configure
The import commands are as follows:
[root@localhost /] # docker import / etc/dhcp/dhcpd.conf > e392026ddd18
(5) deletion of containers
You can use the dockerrm command to delete a container that has been terminated.
An image can contain multiple containers
[root@localhost /] # docker stop e392026ddd18\\ stop e392026ddd18 [root@localhost /] # docker rm e392026ddd18\\ then delete e392026ddd18 [root@localhost /] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5. Docker resource control
Cgroup, short for Controlgroup, is a mechanism provided by the Linux kernel to limit the physical resources used, which mainly include CPU. Memory, blkio. Let's talk about how Docker is managed using the Cgroup mechanism in these three aspects.
(1) limit the rate of CPU usage
For example, set the CPU usage of the container 60ff4594cc73 to 20000 and limit the CPU usage to 20%:
[root@localhost] # echo 20000 > / sys/fs/ cgroup/ cpu/ system. Slice/docker-60ff4594cc73b5474477 636b25b41f 16e1 66a3606aed22 6522d420d0c296990d. Scope/cpu. Cfs_ quota _ us
(2) share CPU proportionally with multi-task
For example, run three newly created containers A. B, C, and the percentage of CPU resources consumed at 1:1:2 can be done like this:
[root@localhost /] # docker run-tid-- cpu-shares 1024 + Image A [root @ localhost /] # docker run-tid-- cpu-shares 1024 + Image B [root @ localhost /] # docker run-tid-- cpu-shares 2048 + Image C
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.