1, Resource control
1. CPU usage control
Limit the maximum number of containers created by this image to 10% of the total resources
docker run --cpu-quota 10000 centos
2. Prorated distribution
Create two containers, c1 and c2. If there are only two containers, set the weight of the container so that the CPU resources of c1 and c2 account for 33.3% and 66.7%
Docker run - ITD -- name C1 -- CPU shares 512 CentOS (image name)
Docker run - ITD -- name C2 -- CPU shares 1024 CentOS (image name)
3. Restrict the container to use the specified CPU
Specify the use of four CPU s for the image
docker run --name c3 --cpuset-cpus 0001,0010,0100,1000 centos
4. Memory usage limit
Limit the container created to a maximum of 1gb of memory
docker run --name c4 -m 1gb centos
5. Limit the amount of data the container reads from the disk \ device
Limit the container to read only 100mb data of sda disk
docker run -d --device-read-bps /dev/sda:100mb centos
6. Limit the amount of data container writes to disk \ device
Limit the container to write only 100mb data of sda disk
docker run -d --device-write-bps /dev/sda:100mb centos
7. Limit the number of times a container reads a disk \ device
Limit the container to read sda disks only 10 times
docker run -d --device-read-iops /dev/sda:10 centos
8. Limit the number of times a container writes to a disk \ device
Limit the container to write to sda disks only 10 times
docker run -d --device-write-iops /dev/sda:10 centos
2, Docker data volume, data volume container
1. Establish data volume (realize data sharing between container directory and host directory)
Build data volume in interactive mode
docker run -v local directory: container directory -- name container name - it image name / bin/bash "- v" specifies the data volume "- name" newly created container name /var/www:/data1 is preceded by the host directory, and the latter is the container directory (the whole is the process of establishing Association)
2. Establish a data volume container (data sharing between two containers, independent of the host environment)
Set up the container in interactive mode and provide the directory as the container carrier of data volume
docker run -v directory in container... -- name container name - it image name / bin/bash
Mount the data volume of the container providing space to the new container to establish the data volume container
Docker run -- volumes from provides the image name of the space -- name container name - it image name / bin/bash
3, Docker personal image creation
1. Create a new image based on an existing image
2. Create a new image based on the local template
3. Create a new image based on Dockerfile
(1) Create a new image based on an existing image
Create container docker create -it centos /bin/bash Generate a new image Docker commit - M "new" - a "ZY" - P ccbd1395fce9 (container ID / name) ccos:new (generated new image name: label) ● - m description ● - a author information Stop the operation of the container during the generation of - p
(2) Create a new image based on the local template
Download Image Template wget http://download.openvz.org/teuplate/precreated/debian-7.0-x86-minimal.tar.gz //Generate a new image cat debian-7.0-x86-minimal.tar.gz | docker import - daoke:new
(3) Create a new image based on Dockerfile
mkdir apache cd apache vim Dockerfile #Base image based on FROM centos #Maintain the user information of the image MAINTAINER The porject <cloud- ops@centos. org> #Install apache Software with mirror operation instruction RUN yum- y update RUN yum -y install httpd #Open port 80 EXPOSE 80 #Copy home page file ADD index. html /var/www/html/index. html #Copy execution script to image ADD run. sh /run. sh RUN chmod 755 /run. sh #Execute script when starting container CMD[" /run. sh"] vim run.sh #!/bin/bash rm -rf /run/httpd/* exec /usr/sbin/apachectl -D FOREGROUP echo "web test" > index.html //Generating mirrors docker build -t httpd:centos . //New image run container docker run -d -p 1216:80 httpd:centos
4, Docker port mapping
1. Mapping of random ports in the container (mapping range: 49000 ~ 49900)
[root@localhost ~]# docker run -d -P httpd:centos 0820d042e62294c0db107eef0fea8c2c1fca737acb8d91306a6d40e134332bde [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0820d042e622 httpd:centos "/run.sh" 2 seconds ago Up 1 second 0.0.0.0:32768->80/tcp epic_jennings
2. Port specified in the container for mapping
[root@localhost ~]# docker run -d -p 5566:80 httpd:centos 9f65fc007070f36df88304515232a0d5fa357e55926a5f06b48cdf359e6ec9b8 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9f65fc007070 httpd:centos "/run.sh" 4 seconds ago Up 4 seconds 0.0.0.0:5566->80/tcp intelligent_nightingale
3. Interconnection between containers
docker run -itd -P --name web1 centos /bin/bash //Create and run the container named web1, and automatically map the port number docker run -itd -P --name web2 --link web1:web1 centos /bin/bash //Create and run a container named web2,
5, Establish Docker private warehouse
[root@localhost tomcat]# docker pull registry / / download the private warehouse registry [root@localhost nginx]# vim /etc/docker/daemon.json //Add private warehouse address { "insecure-registries" : ["192.168.142.77:5000"], //Private warehouse address "registry-mirrors" : ["https://abc123.mirror.aliyuncs.com"] } //Restart docker [root@localhost nginx]# systemctl stop docker [root@localhost nginx]# systemctl start docker //Building container based on warehouse image [root@localhost nginx]# docker create -it registry /bin/bash 96f91f83a1d58ddee147fe3d141d27d69fa7d3d76c46e3783bef7c1c5d0339bb [root@localhost nginx]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 96f91f83a1d5 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 image label (fill in warehouse address for address) [root@localhost nginx]# docker tag nginx:zhy 192.168.142.77:5000/nginx:zhy //Upload can [root@localhost nginx]# docker push 192.168.142.77:5000/nginx:zhy