Docker
Docker containers can be run multiple times after a build
Dcoker vs. virtual machines: Usually we are running Linux on the system, Linux virtualization on the systems, running various applications in the virtual host, and the virtual machines are completely isolated, while Docker is running Linux on the hardware level and doing Docker on the system. Engine, on the Docker engine, runs a variety of applications, at the bottom is the container. Currently, Docker can only run on 64-bit operating systems and cannot be run on Windows, only under windowns virtual machines.
Docker on the C/s structure, the client and server, in the Docker component, mirroring is usually a complete operating system, and the mirror is read-only, the application is usually run in the container, in a writable case to run. The Docker warehouse is a centrally located mirror
1,docker installation and simple command usage
Tee/etc/yum.repos.d/docker.repo <<-' EOF '
[Dockerrepo]
Name=docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
Enabled=1
Gpgcheck=1
Gpgkey=https://yum.dockerproject.org/gpg
Eof
2,yum Installation
[root@zabbix-3 ~]# yum install docker-engine util-linux
[root@zabbix-3 ~]# systemctl start Docker
[Root@zabbix -3 ~]# Docker search CentOS searching Mirror
[root@zabbix-3
~]# Docker pull CentOS to get a mirror] Using default Tag:latest
Latest: Pulling from Library/centos
A3ed95caeb02:pull complete
da71393503ec:pull complete
Digest:sha256:1a62cd7c7 73dd5c6cf08e2e28596f6fcc99bd97e38c9b324163e0da90ed27562
status:downloaded Newer image for Centos:latest
view mirrors
[Root@zabbix-3 ~]# docker images view mirrors
REPOSITORY TAG IMAGE ID CREATED SIZE
CentOS latest 904d6c400333 3 weeks ago 196.7 MB
Remove Mirror
[Root@zabbix-3 ~]# Docker RMI Delete Mirror
Try to run:
[Root@zabbix-3 ~]# Docker run Centos/bin/echo ' Hello World '
Hello World
[Root@zabbix-3 ~]# Docker run centos/bin/ls/etc/|wc-l
117
[Root@zabbix-3 ~]#
Ps-a to view detailed operational information
[Root@zabbix-3 ~]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORT S NAMES
aacbb56b34f0 CentOS "/bin/ls/etc/" Wuyi seconds ago exited (0) seconds ago Big_khorana
0aaac85decee CentOS "/bin/ls/etc/" about a minute ago exited (0) the seconds ago Compassionate_fermi
971692c3b076 CentOS "/bin/echo ' Hello wor" about a minute ago exited (0) about a minute ago Sharp_wozniak
Enter Docker,--name-it Mirror name/bin/bash
-I: Keep the terminal open
-T: Enable TTY binding to this standard input
If this mirror is not present, it is automatically pull
[Root@zabbix-3 ~]# Docker run--name mydocker-it Centos/bin/bash
[root@de5276472785/]#
The server is interrupted by exiting the container and reconnecting as follows:
Find the ID that needs to be reconnected
[Root@zabbix-3 ~]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
de5276472785 CentOS "/bin/bash" 3 hours ago exited (0) minutes ago Mydocker
aacbb56b34f0 CentOS "/bin/ls/etc/" 3 hours ago exited (0) 3 hours ago Big_khorana
0aaac85decee CentOS "/bin/ls/etc/" 3 hours ago exited (0) 3 hours ago Compassionate_fermi
971692c3b076 CentOS "/bin/echo ' Hello wor" 3 hours ago exited (0) 3 hours ago Sharp_wozniak
Start this ID
[Root@zabbix-3 ~]# Docker start de5276472785
de5276472785
[Root@zabbix-3 ~]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
de5276472785 CentOS "/bin/bash" 3 hours ago up seconds Mydocker
aacbb56b34f0 CentOS "/bin/ls/etc/" 3 hours ago exited (0) 3 hours ago Big_khorana
0aaac85decee CentOS "/bin/ls/etc/" 3 hours ago exited (0) 3 hours ago Compassionate_fermi
971692c3b076 CentOS "/bin/echo ' Hello wor" 3 hours ago exited (0) 3 hours ago Sharp_wozniak
[Root@zabbix-3 ~]#
Run-D, which returns an ID when running in the background
[Root@zabbix-3 ~]# Docker run-d--name Mark CentOS Bash
3b51dff90eb1e76a21a54def1f6e813505951cad1bb5a644abff7e27561be94d
[Root@zabbix-3 ~]#
Docker Delete Container
Stop it first.
[Root@zabbix-3 ~]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b51dff90eb1 centos "bash" 4 hours ago exited (0) 4 hours ago Mark
Delete
[Root@zabbix-3 ~]# Docker RM 3b51dff90eb1
3b51dff90eb1
[Root@zabbix-3 ~]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NA Mes
[Root@zabbix-3 ~]#
Yum Install Util-linux
Into the background container, the first nginx pull down
[Root@zabbix-3 ~]# Docker run-d--name Mynginx
Attach: Using attach in some scenarios may cause the container to exit
We install another tool nsenter, which can access the container space
Install this tool: Yum install Util-linux
We first get the PID of this container
[Root@zabbix-3 ~]# Docker inspect--format ' {{. State.pid}} "Mynginx
8085
Then mount and mount the parameters into the container
[Root@zabbix-3 ~]# nsenter--target 8085--mount--uts--ipc--net--pid
root@5643fa5e6925:/# PS aux
USER PID%cpu%mem VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 0.0 31680 2872? Ss 17:28 0:00 nginx:master process nginx-g daemon off;
Nginx 6 0.0 0.0 32072 1700? S 17:28 0:00 Nginx:worker Process
Root 7 0.0 0.0 20256 1912? S 17:50 0:00-bash
Root 11 0.0 0.0 17492 1160? r+ 17:50 0:00 PS aux
root@5643fa5e6925:/#
root@5643fa5e6925:/etc/nginx# ls/etc/nginx/nginx.conf
/etc/nginx/nginx.conf
root@5643fa5e6925:/etc/nginx# ls/etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf
root@5643fa5e6925:/etc/nginx#
But the official mirror is very simple, many common commands are not, enter the Docker script as follows
[Root@zabbix-3 ~]# Cat in.sh
#!/bin/bash
Cname=$1
cpid=$ (Docker inspect--format "{{. State.pid}} "$CNAME)
Nsenter--target "$CPID"--mount--uts--ipc--net--pid
[Root@zabbix-3 ~]#
[Root@zabbix-3 ~]# chmod +x in.sh
[Root@zabbix-3 ~]#./in.sh Mynginx
root@5643fa5e6925:/# PS Aux|grep Nginx
Root 1 0.0 0.0 31680 2872? Ss 17:28 0:00 nginx:master process nginx-g daemon off;
Nginx 6 0.0 0.0 32072 1700? S 17:28 0:00 Nginx:worker Process
Root 29 0.0 0.0 10988 452? r+ 18:00 0:00 grep nginx
root@5643fa5e6925:/#
After the container is created, Iptables adds a section of the NAT table rule.