Docker basic control command (II)

Docker basic control command (II)

Resource Control

CPU usage control

The 10% limit container mirror this can only build a maximum total resources

docker run --cpu-quota 10000 centos

be divided in portion

Create two container c1 and c2, if only two containers, setting the containers weight so c1 and c2 CPU resources accounted for 33.3% and 66.7%

docker run -itd --name c1 --cpu-shares 512 centos(镜像名)
docker run -itd --name c2 --cpu-shares 1024 centos(镜像名)

CPU limit specified container

Specifies the CPU for four mirror

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

Memory usage restrictions
limit established container can only use up to 1gb memory
docker run --name c4 -m 1gb centos

Limit container disk read \ amount of data device
limits the container sda disk read only data of 100mb
docker run -d --device-read-bps /dev/sda:100mb centos

Limiting the amount of data written to the disk container \ device
limits the container can be written 100mb of data disk sda
docker run -d --device-write-bps /dev/sda:100mb centos

Limit the number of disk reads vessel \ device
limits the container 10 can only read disks sda
docker run -d --device-read-iops /dev/sda:10 centos

Limit the number of disk writes container \ device
limits the container 10 can be written only once disk sda
docker run -d --device-write-iops /dev/sda:10 centos

Docker data volume, the data volume container

Establishing data volume (data sharing between the host and the recording destination directory in the container)

Establish a data volume in interactive mode

docker run -v 本地目录:容器目录 --name 容器名 -it 镜像名 /bin/bash

"-V" specified data volume

Container name "-name" newly established

/ Var / www: / data1 front of the home directory, which directory container (whole association process)

Establishing a data volume container (data sharing between the two containers, regardless of the host environment)

Establishing interactive mode and provides a container wherein the container volume data directory as the carrier

docker run -v 容器内目录 ...... --name 容器名 -it 镜像名 /bin/bash

Mount space of the container provided to establish the data volume of the data volume to a new container vessel

docker run --volumes-from 提供空间的镜像名 --name 容器名 -it 镜像名 /bin/bash

Docker personal image creation

Create a new image based on an existing image

Create a new image based on local templates

Create a new image-based Dockerfile

Create a new image based on an existing image

# Create a container
docker create -it centos /bin/bash
# generate a new image
docker commit -m "new" -a "zhy" -p ccbd1395fce9(容器ID/名称) ccos:new(生成的新镜像名称:标签)
● -m description information
● -a author information,
stop the container ● -p generated during operation

Create a new image based on local templates

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

Create a new image-based Dockerfile

mkdir apache
cd apache

vim Dockerfile
#基于的基础镜像
FROM centos
#维护镜像的用户信息
MAINTAINER The porject <cloud- ops@centos. org>
#镜像操作指令安装apache软件
RUN yum- y update
RUN yum -y install httpd
#开启80端口
EXPOSE 80
#复制网站首页文件
ADD index. html /var/www/html/index. html
#将执行脚本复制到镜像中
ADD run. sh /run. sh
RUN chmod 755 /run. sh
#启动容器时执行脚本.
CMD[" /run. sh"]

vim run.sh
#!/bin/bash
rm -rf /run/httpd/*
exec /usr/sbin/apachectl -D FOREGROUP
echo "web test" > index.html
//生成镜像
docker build -t httpd:centos .
//新镜像运行容器
docker run -d -p 1216:80 httpd:centos

Docker port mapping

Random port mapping (range: 49,000 - 49,900) in the container

[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

Mapping the designated port within the vessel

[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

Interconnection between the container

docker run -itd -P --name web1 centos /bin/bash                      //创建并运行容器取名web1,端口号自动映射
docker run -itd -P --name web2 --link web1:web1 centos /bin/bash                    //创建并运行容器取名web2,

Docker private warehouse

[root@localhost tomcat]# docker pull registry              //下载私有仓库注册表
[root@localhost nginx]# vim /etc/docker/daemon.json
//添加私有仓库地址
{
  "insecure-registries" : ["192.168.142.77:5000"],                       //私有仓库地址
  "registry-mirrors" : ["https://abc123.mirror.aliyuncs.com"]
}

//重启docker
[root@localhost nginx]# systemctl stop docker
[root@localhost nginx]# systemctl start docker

//基于仓库镜像建立容器
[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

//更改镜像标签(地址填写仓库地址)
[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

Guess you like

Origin blog.51cto.com/14484404/2461754