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

Docker basic Control commands (2)

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Docker Basic Control Command (II) Resource Control

CPU utilization control

Limit the containers created by this mirror to 10% of the total resources at most

docker run --cpu-quota 10000 centos

be prorated

Create two containers c1 and c2. If there are only these two containers, set the weights of the containers so that the CPU resource ratios of c1 and c2 are 33.3% and 66. 7%

docker run -itd --name c1 --cpu-shares 512 centos

docker run -itd --name c2 --cpu-shares 1024 centos

Restrict containers from using specified CPUs

Specify four CPU usage for this mirror

docker run --name c3 --cpuset-cpus 0001,0010,0100,1000 centos

memory usage limit

Limit the container you create to a maximum of 1 GB of memory

docker run --name c4 -m 1gb centos

Limit the amount of data containers can read from disks\devices

Limit this container to reading only 100mb of data from sda disks

docker run -d --device-read-bps /dev/sda:100mb centos

Limit the amount of data containers can write to disk\devices

Limit this container to writing only 100MB of data to the sda disk

docker run -d --device-write-bps /dev/sda:100mb centos

Limit the number of times a container reads disks\devices

Limit the container to reading the sda disk 10 times

docker run -d --device-read-iops /dev/sda:10 centos

Limit the number of times a container writes to disk\device

Limit this container to 10 writes to sda disk

docker run -d --device-write-iops /dev/sda:10 centos

Docker volumes, volume containers

Create a data volume (sharing data between container directories and host directories)

Creating data volumes in interactive mode

docker run -v local directory: container directory--name container name-it image name/bin/bash

"-v" specifies the data volume

"-name" Name of newly created container

/var/www:/data1 is preceded by the host directory, and the latter is the container directory (the whole process of establishing associations)

Create a data volume container (data sharing between two containers, independent of the host environment)

Create containers in interactive mode and provide directories therein as data volume container carriers

docker run -v Contents in container... --name Container name-it Image name/bin/bash

Mount the data volume of the container providing space into a new container to create a data volume container

docker run --volumes-from image name--name container name--it image name/bin/bash

Docker personal image creation

Create a new mirror based on an existing mirror

Create a new mirror based on a local template

Create a new mirror based on Dockerfile

Create a new mirror based on an existing mirror

#Creating containers

docker create -it centos /bin/bash

#Create a new image

docker commit -m "new" -a "zhy" -p ccbd1395fce9(container ID/name) ccos:new (name of new image generated: label)

●-m Description information

●-a Author information

●-Stop container operation during p generation

Create a new mirror based on a local template

#Download Mirror Template

wget http://download.openvz.org/teuplate/precreated/debian-7.0-x86-minimal.tar.gz

#Create a new image

cat debian-7.0-x86-minimal.tar.gz | docker import - daoke:new

Create a new mirror based on Dockerfile

mkdir apachecd apachevim Dockerfile#Base image based on FROM centos#Maintains user information of image MAINTAINER The porject #Mirror operation instruction install apache software RUN yum- y updateRUN yum -y install httpd#Open port 80 EXPOSE 80 #Copy website home file ADD index. html /var/www/html/index. html#Copy execution script to mirror ADD run. sh /run. shRUN chmod 755 /run. sh#Execute script when starting container.CMD[" /run. sh"]vim run.sh#!/ bin/bashrm -rf /run/httpd/*exec /usr/sbin/apachectl -D FOREGROUPecho "web test" > index.html//generate mirror docker build -t httpd:centos .// new image run container docker run-d-p 1216:80 httpd:centosDocker port mapping

Random port mapping in container (mapping range: 49000~49900)

[root@localhost ~]# docker run -d -P httpd:centos 0820d042e62294c0db107eef0fea8c2c1fca737acb8d91306a6d40e134332bde[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES0820d042e622 httpd:centos "/run.sh" 2 seconds ago Up 1 second 0.0.0.0:32768->80/tcp epic_jennings

Specify port mapping in container

[root@localhost ~]# docker run -d -p 5566:80 httpd:centos9f65fc007070f36df88304515232a0d5fa357e55926a5f06b48cdf359e6ec9b8[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9f65fc007070 httpd:centos "/run.sh" 4 seconds ago Up 4 seconds 0.0.0.0:5566->80/tcp intelligent_nightingale

interconnection between containers

docker run -itd -P --name web1 centos /bin/bash //Create and run container named web1, port number automatically mapped docker run-itd-P --name web2 --link web1: web1 centos /bin/bash //create and run a container named web2,Docker private repository [root@localhost tomcat]# docker pull registry //Download private repository registry [root@localhost nginx]# vim /etc/docker/daemon.json//Add private repository address { "insecure-registries" : ["192.168.142.77:5000"], //Private repository address "registry-mirrors" : ["https://abc123.mirror.aliyuncs.com"]}//Restart docker[root@ localhost nginx]# systemctl stop docker[root@ localhost nginx]# systemctl start docker//Create container based on repository image [root@localhost nginx]# docker create -it registry /bin/bash96f91f83a1d58ddee147fe3d141d27d69fa7d3d76c46e3783bef7c1c5d0339bb[root@localhost nginx]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES96f91f83a1d5 registry "/entrypoint.sh /bin…" 5 seconds ago Created sweet_almeida[root@localhost nginx]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry//Change the image tag (fill in the repository address)[root@localhost nginx]# docker tag nginx:zhy 192.168.142.77:5000/nginx:zhy [root@localhost nginx]# docker push 192.168.142.77:5000/nginx:zhy

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: 223

*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

Servers

Wechat

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

12
Report