Docker is already very popular. It is based on the three technologies of Linux namespace, control group and UnionFS. Using docker can isolate applications from each other without interfering with each other; compile once and run everywhere.
Namespaces are methods used to separate resources such as process trees, network interfaces, mount points, and inter-process communication.
Control Groups (CGroups for short) can isolate physical resources on the host machine, such as CPU, memory, disk I/O, and network bandwidth. A CGroup has a set of processes with the same standards and parameter restrictions.
UnionFS is a file system service used to " unify " multiple file systems to the same mount point. [1]
Basic installation and use
- Install the required software packages, yum-util provides the yum-config-manager function, and the other two are dependent on the devicemapper driver
yum install -y yum-utils device-mapper-persistent-data lvm2
- Set source, priority domestic, fast
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
-
Update yum package index
yum makecache fast -
Install Docker CE
yum install docker-ce -
启动
systemctl start docker
systemctl enable docker -
Pull to the mirror docker pull centos: centos7.2.1511 -
Others
Create a container and specify the network card mode
docker run ---privileged=true -itd --name demo --network=host centos:7.2.1511
docker mount directory
docker run -d -e "container=docker" ---privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup ---name centos:centos7.2.1511 /usr/sbin/init
docker install mariadb directly
docker run --privileged -d --restart=always -e TIMEZONE=Asis /Shanghai -e MYSQL_ROOT_PASSWORD=root -e SERVER_ID=1 -v /opt/data/mariadb/dbdata:/var/lib/mysql -p 3306:3306 mariadb --character-set-server=utf8mb4 --collation-server= utf8mb4_unicode_ci -
Common docker commands
View image docker images
View container docker ps -a
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
blackboxback latest f8ae50a0e292 6 months ago 834MB
centos 7.2.1511 9aec5c5fe4ba 22 months ago 195MB
centos centos7.2.1511 9aec5c5fe4ba 22 months ago 195MB
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91237e59bea0 centos:7.2.1511 "/usr/sbin/init" 6 months ago Exited (255) 5 months ago xx1
39d81809cd27 centos:7.2.1511 "/usr/sbin/init" 6 months ago Exited (255) 5 months ago xx2
a068fa9a4b7f centos:7.2.1511 "/usr/sbin/init" 6 months ago Exited (255) 6 months ago hhp
2865ab62ca5f centos:7.2.1511 "/usr/sbin/init" 6 months ago Exited (137) 6 months ago hhproxy
67d02ea71169 centos:7.2.1511 "/usr/sbin/init" 6 months ago Exited (255) 6 months ago proxy
Reference:
[0] https://www.runoob.com/docker/docker-install-centos.html
[1] https://www.linuxprobe.com/docker-technology-principle.html