Introduction tutorial and deployment of docker
1. Docker introduction:
01) Docker is an open source application container engine based on Go language And comply with Apache 2 0 protocol is open source.
02) Docker allows developers to package their applications and dependency packages into a lightweight and portable container, and then publish them to any popular Linux machine. It can also realize virtualization.
03) the container completely uses the sandbox mechanism, and there will be no interface between them (similar to iPhone app). More importantly, the performance overhead of the container is very low.
04) Docker is divided into CE (Community Edition) and EE (Enterprise Edition) after version 17.03. We can use the Community Edition.
In the field of computer security, sandbox is an isolated running mechanism of programs;
2. Who is suitable for reading this tutorial?
This tutorial is suitable for operation and maintenance engineers and back-end developers. Through this tutorial, you can understand the use of Docker step by step.
Before reading this tutorial, you need to master the common commands of Linux.
3. Application scenario of Dock:
- Automated packaging and publishing of Web applications.
- Automated testing and continuous integration and release.
- Deploy and adjust databases or other background applications in a service-oriented environment.
- Compile or extend the existing OpenShift or Cloud Foundry platform from scratch to build your own PaaS environment.
4. Advantages of Docker:
Docker is an open platform for developing, delivering and running applications. Docker enables you to separate your applications from your infrastructure so that you can deliver software quickly. With docker, you can manage your infrastructure the same way you manage your applications. By using docker's method to quickly deliver, test and deploy code, you can greatly reduce the delay between writing code and running code in a production environment.
01) quickly and consistently interact with your application;
02) responsive deployment and expansion;
03) run more workloads on the same hardware;
5. Docker architecture:
Docker has three components:
- Image: Docker image is equivalent to a template.
- Container: the relationship between an Image and a container is like a class and instance in object-oriented programming. An Image is a static definition, and a container is an entity when the Image runs. Containers can be created, started, stopped, deleted, paused, and so on.
- Repository: a repository can be regarded as a code control center for storing images.
Docker uses client server (C/S) architecture mode and remote API s to manage and create docker containers.
Docker containers are created through docker images.
6. Underlying principle of Docker:
- cgroup and namespaces constitute the underlying principle of docker;
- cgroup resource control and namespaces control and manage six namespace resources (as follows):
- The container isolates six namespaces (namespace resource isolation - encapsulated with containerization Technology)
- Mount file mount point. A specified directory cannot be mounted repeatedly in a file system, for example: / mnt;
- User the user and user group of the operation process;
- pid process number;
- uts host name and host domain;
- ipc semaphores, message queues, and shared memory (understand that different applications should use different memory spaces when calling memory resources);
- net network equipment, network protocol stack, port, etc;
7. Compare Docker and virtual machine technologies:
1. The traditional virtual machine virtualizes a piece of hardware, runs a complete operating system, and then installs and runs software on this system.
2. The applications in the container run directly in the kernel of the host. The container does not have its own kernel or virtual hardware, so it is lightweight.
3. Each container is isolated from each other. Each container has its own file system, which does not affect each other.
8. Deploy Centos Docker
(1) . automatic installation using official installation script:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun #You can also use the domestic daocloud one click installation command curl -sSL https://get.daocloud.io/docker | sh
(2) Manual installation:
01. First uninstall the old version:
The older version of docker is called docker or docker engine. If you have installed these programs, uninstall them and their related dependencies.
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
02. Close the firewall, SELinux, and modify the server name:
systemctl stop firewalld.service systemctl disable firewalld.service setenforce 0 hostnamectl set-hostname docker
03. Install Docker using YUM warehouse
Install dependent packages:
yum install -y yum-utils device-mapper-persistent-data lvm2
Set alicloud image source:
cd /etc/yum.repo.d yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
04. Install docker CE
yum install -y docker-ce systemctl start docker.service systemctl enable docker.service
05. Image acceleration:
Each account has its own image accelerator;
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://yagayyvn.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
06. Network optimization:
vim /etc/sysctl.conf net.ipv4.ip_forward=1 sysctl -p systemctl restart network systemctl restart docker #Query image list docker images
07. Docker related commands:
#View docker version docker version docker info
Here, some configuration files are extended:
vim /etc/docker/daemon.json ##The docker configuration file can also add the following establishment configurations: { "graph": "/data/docker", ##Data directory "storage-driver": "overlay2", ##Storage engine; Version iteration: LXC - > overlay - > overlay 2 (overlay FS: file system, which solves the image layering of docker) "insecure-registries": [" registry.access.redhat.com", "quary.io"] ##Private warehouse location "registry-mirrors": ["https://q***"] ## Image acceleration "bip": "172.7.5.1/24", ##Docker network; Position of control network segment; You need to create a new bridge. The default docker0 of the system remains unchanged "exec-opts": ["native.cgroupdriver-systemd"], ##Additional parameters at startup (drive) "live-restore":true ##When the docker container engine hangs, the container running with docker can still run (separate) }
Run mirror:
#Run mirror docker run hello-world ##Run the Hello world image run Represents the following: ①: pull dockerhub Download items in warehouse/library/image ②: start hello-world image #Search image docker search nginx ##Search image nginx docker search centos: 7 ##Search image centos:7 #Download Image - pull #The client connects to the server and downloads the image from the docker hub Format: docker pull Image name docker pull nginx ##Download the latest image of nginx #View mirror docker images ##View mirror list docker images -q ##Query image filter ID #q: Representative filtering; Filter container ID only