Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

1. Introduce Docker

1.1 What is a container?

The container

1.2 Previous lives of containers

FreeBASE jail -> Linux vserver

  • Chroot: Full root file system (FHS) standard

  • Namespaces: UTS Mount IPC PID user network

  • Cgroup: Allocates and monitors resources

Through the process of complex code development, the above three technologies are called to achieve the creation, management and destruction of containers

1.3 Comparison between traditional virtualization technologies and Containers

1.4 The Life of containers

Isolation capability!

LXC -> Docker

LXC (LinuXContainer) encapsulates the original common functions to facilitate container lifecycle management

2. Docker installation

2.1 Environment Preparation


curl http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

Copy the code

2.2 Installing dependency packages


yum install -y yum-utils device-mapper-persistent-data lvm2

yum list docker-ce.x86_64 --showduplicates | sort -r

Copy the code

2.3 installation docker – ce

• Obsoletes =0 \ docker-ce-17.03.2. Ce-1.el7.centos.x86_64 \ Docker - ce - selinux - 17.03.2. Ce - 1. El7. Centos. NoarchCopy the code

2.4 Starting the Docker Service


systemctl daemon-reload

systemctl restart docker

docker version

docker info

Copy the code

2.5 Configuring Mirror Acceleration


vim /etc/docker/daemon.json

{

"registry-mirrors": ["https://68rmyzg7.mirror.aliyuncs.com"]

}

Copy the code

Docker architecture

Registry:

  1. User authentication

  2. Image indexing

  3. Image storage

4. Docker image foundation management

4.1 Obtaining a Mirror

Docker search centos docker pull centos:6.9 docker pull centos:7.5.1804 docker pull nginxCopy the code

4.2 Querying a Mirror

4.2.1 Viewing a Mirror

[root@VM-0-3-centos ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 35c43ace9216 7 days ago 133 MB Centos 7.5.1804 CF49811e3CDB 23 months ago 200 MBCopy the code

REPOSITORY represents the image name.

Some image names are XXX /centos. The images without/are officially released, while the images with/are released by individuals or other companies. When you choose, just choose the star.

TAG indicates the version number.

REPOSITORY:TAG identifies the image as unique.

IMAGE ID indicates the IMAGE ID, which is sha256: 64-bit number. By default, only 12 digits are captured.

Docker image ls –no-trunc

[root@VM-0-3-centos ~]# docker image ls --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest Sha256 35 c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151 7 days in a line 133 MB centos 6.9 Sha256:2199 b8eb8390197d175b1dd57ed79f53ed92ffa58e23826ada54113262237e56 23 up line 195 MB centos 7.5.1804 sha256:cf49811e3cdb94cbdfd645f3888d7add06a315449cf2c7ca7b81c312f1e46c63 23 months ago 200 MBCopy the code

4.2.2 Querying the Mirror ID Separately


[root@VM-0-3-centos ~]# docker images -q

35c43ace9216

2199b8eb8390

cf49811e3cdb

Copy the code

4.2.3 Viewing Mirror Information in detail


docker image inspect nginx:latest

Copy the code

4.3 Importing and Exporting an Image


docker image save nginx:latest > /tmp/nginx.tar

docker image load -i /tmp/nginx.tar

Copy the code

4.4 Deleting a Mirror

Rm [image ID] // Delete all images docker rmi 'docker images -q' docker RMI $(docker images -q) // Forcibly delete -f docker image rm -f 35c43ace9216Copy the code

4.5 Resetting labels

Preparations:

// Export the mirror, [root@VM-0-3-centos TMP]# docker image save 35c43ace9216 > / TMP /nginx1.va // import image [root@VM-0-3-centos TMP]# Docker images REPOSITORY TAG image ID CREATED docker image load -i/TMP /nginx1 SIZE <none> < None > 35c43ACE9216 7 days ago 133 MB centos 6.9 2199b8eb8390 23 months ago 195 MB centos 7.5.1804 Cf49811e3cdb 23 months ago 200 MB // If the IMAGE is exported using a REPOSITORY TAG, the IMAGE is also imported using a REPOSITORY TAG. // Manually add REPOSITORY:TAG [root@VM-0-3-centos TMP]# docker image TAG 35c43ace9216 nginx:v1 [root@VM-0-3-centos tmp]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v1 35c43ace9216 7 days ago 133 MB Centos 7.5.1804 cf49811e3cDB 23 months ago centos 7.5.1804 cf49811e3cDB 23 months ago [root@VM-0-3-centos TMP]# docker pull nginx [root@VM-0-3-centos TMP]# docker image ls --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest sha256:35c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151 7 days ago 133 MB nginx v1 Sha256 35 c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151 7 days in a line 133 MB centos 6.9 Sha256:2199 b8eb8390197d175b1dd57ed79f53ed92ffa58e23826ada54113262237e56 23 up line 195 MB centos 7.5.1804 Sha256: cf49811e3cdb94cbdfd645f3888d7add06a315449cf2c7ca7b81c312f1e46c63 23 up line: 200 MB / / we'll to nginx latest image changes The tag, [root@VM-0-3-centos TMP]# docker image tag 35c43ace9216 nginx:v2 [root@VM-0-3-centos TMP]# docker image ls --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest sha256:35c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151 7 days ago 133 MB nginx v1 sha256:35c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151 7 days ago 133 MB nginx v2 Sha256 35 c43ace9216212c0f0e546a65eec93fa9fc8e96b25880ee222b7ed2ca1d2151 7 days in a line 133 MB centos 6.9 Sha256:2199 b8eb8390197d175b1dd57ed79f53ed92ffa58e23826ada54113262237e56 23 up line 195 MB centos 7.5.1804 sha256:cf49811e3cdb94cbdfd645f3888d7add06a315449cf2c7ca7b81c312f1e46c63 23 months ago 200 MBCopy the code