Docker
一、basic operation
1、installation("https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11xKAp2g")
2、docker
(1)systemctl start docker
(2)docker search appName
(3)docker pull appName
3、image
(1)docker images
(2)docker rmi imageName/imageID
(3)docker run imageName/imageID
(4)docker run centos /bin/echo 'Hello World'
(5)enter into docker container----->docker run --name mydocker -it centos /bin/bash(-t:tty)---->exit
(6)docker run -d --name mydocker1
4、container
(1)docker ps (-a/-l)
(2)docker start containerName/containerID
(3)docker stop containerName/containerID
(4)docker attach containerName/containerID
(5)docker exec containerName/containerID /bin/bash
(6)docker inspect --format "{{.State.Pid}}" containerName/containerID(nsenter --target Pid --mount --uts --ipc --net --pid)
(7)script-->in.sh
1 #!/bin/bash 2 CNAME=$1 3 CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME) 4 nsenter --target "$CPID" --mount --uts --ipc --net --pid
二、network
1、Mapping
(1)random mapping:docker run -P
(2)specify mapping:
(2.1)-p hostPort:ContainerPort
(2.2)-p ip:hostPort:ContainerPort
(2.3)-p ip::ContainerPort
2、brctl show
3、ip ad li(ip ro li)
4、iptables -t nat -L -n
三、data management
1、data volume
(1)-v /data
(1.1)docker run -it --name volume-test1 -h nginx -v /data nginx
(1.2)docker inspect -f {{.Volumes}} volume-test1
(2)-v src:dst
(1.1)docker run -it --name volume-test1 -h nginx -v src:dst nginx
2、data volume container
(1)--volumes-from
docker run -it --name volume-test4 --volumes-from volume-test1 nginx
四、image
1、manual build
(1)basic operation
1 docker search centos 2 docker pull centos 3 docker run --name centos-manual -it centos 4 yum install -y wget gcc gcc-c++ openssl-devel make 5 wget http://nginx.org/download/nginx-1.19.2.tar.gz 6 wget ftp://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz 7 mv *.gz /usr/local/src/ && cd /usr/local/src/ 8 tar zxvf pcre-8.37.tar.gz && rm -rf pcre-8.37.tar.gz 9 tar zxvf nginx-1.19.2.tar.gz && rm -rf nginx-1.19.2.tar.gz 10 cd nginx-1.19.2/ && useradd -s /sbin/nologin -M www 11 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37/ 12 make && make install 13 vi /usr/local/nginx/conf/nginx.conf-->daemon off;
14 exit
(2)make image-->docker commit -m "message" containerID imageName
(2.1)docker commit -m "my nginx" 74c491e749fc predator/my-nginx:v1(sha256:37c64602734a130156c089e6f4f8369812cc25261ba1ee3833629aca62646d1a)
(2.2)docker run -d -p 80:80 predator/my-nginx:v1 /usr/local/nginx/sbin/nginx
2、Dockfile(mkdir /opt/docker-file/nginx-->vim Dockerfile)
1 # This is my first Dockerfile 2 # Version 1.0 3 # Author:predator 4 5 #Basic images 6 FROM centos 7 8 #Maintainer information 9 MAINTAINER predator 10 11 #ADD 12 ADD pcre-8.37.tar.gz /usr/local/src 13 ADD nginx-1.19.2.tar.gz /usr/local/src 14 15 #RUN 16 RUN yum install -y wget gcc gcc-c++ make openssl-devel 17 RUN useradd -s /sbin/nologin -M www 18 19 #WORKDIR 20 WORKDIR /usr/local/src/nginx-1.19.2 21 RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37/ && make && make install 22 RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf 23 24 ENV PATH /usr/local/nginx/sbin:$PATH 25 EXPOSE 80 26 27 CMD ["nginx"]
docker build -t nginx-file:v1 /opt/docker-file/nginx/
(1)basic image information-->FROM
(2maintainer information-->MAINTAINER
(3)image operate instructions
(3.1)RUN
(3.2)ADD(ADD pcre-8.37.tar.gz /usr/local/src/)
(3.3)WORDIR
(3.4)VOLUME
(3.5)EXPOSE
(4)execute instructions when container starting-->RUN
五、resource isolation and restriction
1、docker pull registry
2、mkdir /opt/docker-file/stress && cd /opt/docker-file/stress
3、wget http://mirrors.aliyun.com/repo/epel-7.repo
4、vim Dockerfile
1 FROM centos 2 ADD epel-7.repo /etc/yum.repos.d/ 3 RUN yum -y install stress && yum clean all 4 ENTRYPOINT ["stress"]
5、docker build -t stress .(cat /proc/cpuinfo)
6、docker run -it --rm stress --cpu 1
7、docker run -it --rm -m 128m stress --vm 1 --vm-bytes 128m --vm-hang 0
8、docker run -d -p 5000:5000 registry
9、docker tag elasticsearch xxx.xxx.x.xxx:5000/test/es:v1
10、docker push xxx.xxx.x.xxx:5000test/es:v1
11、vim /etc/sysconfig/docker-->other_args="--insecure-registry xxx.xxx.x.xxx:5000"-->systemctl restart docker