In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Docker Overview
What is Docker? Is a lightweight "virtual machine" in Linux container running applications open source tools Docker use scenarios packaged applications simplified deployment can be separated from the underlying hardware arbitrary migration Docker core concept image container repository public repository: official private repository: private build Note: input and container can be converted to each other! Two ways to install Docker on CentOS Use CURL to get Docker installation script for installation Use YUM repository to install Docker Note: YUM installation is recommended! docker install host OS IP address Primary software server CentOS7192.168.142.130Docker-19.003.0-ce#install dependency package yum install -y yum-utils device-mapper-@ sistent-data lvm 2#Set Aliyun mirror source yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#Install Docker-CEyum install docker-ce -y#Turn off firewall and security functions systemctl stop firewalld.servicesetenforce 0#Turn on dockersystemctl start docker.service#Boot up and start dockersystemctl enable docker.service#View service process status ps aux| grep dockerdocker basics #view docker version#public repository search image docker search nginx#download image (too slow!) docker pull Repository Name [: Tags]
Examples:
docker pull nginx#overload daemon systemctl daemon-reload#restart service systemctl restart docker#view downloaded images docker images#view image details docker inspect image ID #add new tag docker tag name [: tag] new name [: new tag]#delete image docker rmi repository name [: tag]docker rmi image ID#save image docker save -o save image name saved image #load image docker load --input save file name docker load
< 存出文件名#上传镜像docker push 仓库名称[:标签]docker容器操作#创建容器docker create [选项]镜像运行的程序#选项-i让容器的标准输入保持打开-t让Docker分配一个伪终端**实例:**```bashdocker create -it nginx:latest /bin/bash#查看容器docker ps [选项]#选项-a:列出最近一次启动的容器-q:静默模式,只显示容器编号 实例: docker ps -a#启动容器docker start 容器ID#创建容器并执行shell命令docker run [选项]镜像运行的程序,执行的命令#选项-p:可以指定映射端口;-P:将容器开放的网络端口(默认是80端口)映射到主机随机的一个端口;-d:在后台进行运行#持续在后台执行docker run -d 容器名称 /bin/bash -c "while true;do echo hello;done"#终止容器docker stop 容器的ID/名称#进入容器,容器一定要处于up状态docker exec p[选项]容器的ID/名称 /bin/bashdocker exec -it 容器ID /bin/bash#选项-i : 即使没有连接,也保持STDIN 打开;-t : 分配一个伪终端,这样就可以看到 Linux 命令提示符了;#退出容器exit #导出容器docker export 容器的ID/名称ID >filename #Import container (images are generated, containers are not created) cat filename| docker import -name of image generated: tag #delete container docker rm [options] ID/name of container #bulk delete docker ps -a| awk '{print "docker rm "$1}' |bashdocker resource control
1. Limit CPU usage
● Limit CPU usage with--cpu-quota option ● By modifying the configuration file cpu.cfs_quota_us
Examples:
docker run --cpu-quota 20000 centos
2. Multitasking proportionally shares CPU
docker run --cpu-shares 1024 container Adocker run --cpu-shares 1024 container Bdocker run --cpu-shares 2048 container C
Examples:
#Proportional allocation #Create two containers c1 and c2. If there are only two containers, set the weights of the containers so that the CPU resources of c1 and c2 account for 33.3% and 166.7% respectively. locker run -itd --name c1 --cpu-shares 512 paigeeworld/centos7locker run -itd --name c2 --cpu-shares 1024 paigeewor1d/centos7
3. Use the--cpuset-cpus option to restrict CPU kernel usage
docker run- -m 512m paigeeworld/ centos7
4. Restrictions on blkio
--device-read-bps: Limit bps (data volume) read from a device
Examples:
docker run -d --device-read-bps /dev/sda: 30M paigeeworld/centos7--device-write-bps : Limit bps (amount of data) written to a device
Examples:
docker run -d --device-write-bps dev/sda: 30M pai geewor ld/ centos7--device-read-iops : Limit iops (number of times) reading a device--device-write-iops : Limit iops (number of times) writing to a device Docker's data management
data management operations
Easy to view the data generated in the container to achieve data sharing between multiple containers
Two Management Methods
volume (sharing between container and host) volume container (sharing between containers)docker volume volume A volume is a special directory that provides container usage #Create a volume docker run-d -V /data1-V /data2--name web httpd:centos#Mount a host directory as a volume docker run -d -V /var/www:/data1--name web-1 httpd:centos#Mount a volume from a web container to a new container docker run -it --volumes-from web --name db1 httpd:centos /bin/bash
Examples:
#download image docker pull centos#host directory/var/www mount container/data1docker run -v /var/www:/data1--name web1 -it centos /bin/bash#create test cd /data1/touch test#exit container exit#return to host to view ls /var/www[root@localhost ~]# ls /var/wwwtestdocker data volume container #data volume container docker run --name web100 -v /data1-v /data2-it centos /bin/bash#new container mount data volume container web100docker run -it --name db1 centos /bin/bash Thank you for reading!!
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.