I recently started to learn about docker and found that the introduction is different from each other. Many of the materials described here are from the Internet, and many are from personal understanding.
I. What is Docker and why docker is used.
To learn about docker, you must always remember one sentence: "one package, run everywhere ."
1. Concepts.
Docker is an open-source engine that can automatically deploy development applications to containers. It is compiled by a Docker team and authorized based on the Apache 2.0 Open Source protocol. It provides a simple and lightweight modeling method to make the development lifecycle more efficient and fast, and encourages service-oriented architecture design. The goal of the Docker project is to implement a lightweight OS virtualization solution. Docker is based on Linux containers (LXC) and other technologies. On the basis of LXC, Docker further encapsulates the container so that users do not need to care about container management, making the operation easier. Operations on Docker containers are as simple as operations on a fast and lightweight virtual machine. "One encapsulation, run everywhere ."
First, Docker containers can be started in seconds, which is much faster than traditional virtual machines.
Secondly, Docker has a high utilization of system resources, and thousands of Docker containers can be run simultaneously on a single host. In addition to running applications, containers basically do not consume additional system resources, resulting in high application performance and minimal system overhead. In traditional virtual machines, 10 virtual machines are required to run 10 different applications, while Docker only needs to start 10 isolated applications.
2. Docker has great advantages in the following aspects.
2.1 faster delivery and deployment
For developers and O & M personnel, the most desired task is to create or configure a configuration, which can run properly anywhere.
Developers can use a standard image to build a set of development containers. After development, O & M personnel can directly use this container to deploy code. Docker can quickly create containers, quickly iterate applications, and make the entire process visible, so that other members in the team can easily understand how the applications are created and work. Docker containers are very light and fast! The start time of the container is several seconds, greatly saving the development, testing, and deployment time.
2.2 More efficient virtualization
The running of Docker containers does not require additional hypervisor support. It is kernel-level virtualization, so it can achieve higher performance and efficiency.
2.3 easier migration and expansion
Docker containers can run on almost any platform, including physical machines, virtual machines, public clouds, private clouds, PCs, and servers. This compatibility allows you to directly migrate an application from one platform to another.
2.4 simpler management
With Docker, you only need a small modification to replace a lot of previous updates. All modifications are distributed and updated incrementally to achieve automated and efficient management.
Compared with traditional virtual hosts:
1
3. Three core concepts in Docker: Images, containers, and warehouses
A Docker container is essentially a process on the host. Docker achieves resource isolation through namespace, implements resource restrictions through cgroups, and implements efficient file operations through the copy-on-write mechanism.
Docker has five namespaces: Process, network, mount, host, and shared memory. To isolate problematic applications, Docker uses Namespace to isolate processes, creates an isolated runtime space for a process or process group and provides different namespace views for the process. In this way, each isolated process Group is represented as a container ). Note that Docker allows users to mistakenly assume that they occupy all resources, but this is not a "virtual machine ".
(1) image: A Docker image is a read-only template that can be used to create a Docker container. Docker provides a simple mechanism to create an image or update an existing image. Users can even directly download an existing image from others for direct use.
An image is a file structure. Each command in Dockerfile creates a new hierarchy in the file system. When the file system is built on these layers, the image is built on these associated file systems.
The official Docker website has a page to store all available images. The website is index.doc ker. io.
(2) Container: a running instance created from an image. It can be started, started, stopped, or deleted. Each container is an isolated and secure platform. We can regard containers as a simple version of Linux environment. Docker uses containers to run applications. The image is read-only. When the container is started, a writable layer is created as the top layer.
(3) warehouse: a warehouse stores image files in a centralized manner. The Registry usually stores multiple warehouses. Each warehouse contains multiple images, each image has different tags ). Currently, the largest public repository is Docker Hub, which stores a large number of images for users to download.
The Docker repository is used to save our images. After we create our own image, we can use the push command to upload it to the public or private repository, in this way, the next time you want to use this image on another machine, you only need to use pull from the warehouse. The concept of Docker repository is similar to that of Git. The registration server can be understood as a hosting service such as GitHub.
2. Install Docker.
Prerequisites: Docker has high requirements on the kernel. The centos system is introduced here as an example. Other systems are not described here. Centos7 (64-bit), centos 6.5 (64-bit), and later do not support 32-bit running. When running centos 6.5 and later versions, kernel version> = 2.6.32-431 is required because these kernels contain specific modifications to run Docker.
1. Install docker on centos 7.x
The Docker RPM package is already included in the centos-Extra repository, so we can install it directly using yum:
Yum-y install docker
2. Install docker in centos 6.5
First install the epel Source:
Yum-y install epel-release
Install docker:
Yum-y install docker-io
[Root @ docker1 yum. repos. d] #/etc/init. d/docker start # start docker
Starting cgconfig service: [OK]
Starting docker: [OK]
[Root @ docker1 yum. repos. d] # docker info # Description: docker info # View basic docker information
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: docker-253: 0-139088-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file:/dev/loop0
Metadata file:/dev/loop1
Data Space Used: 305.7 MB
Data Space Total: 107.4 GB
Data Space Available: 4.474 GB
Metadata Space Used: 729.1 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file:/var/lib/docker/devicemapper/data
Metadata loop file:/var/lib/docker/devicemapper/metadata
Library Version: 1.02.117-RHEL6 (2016-04-01)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-642.1.1.el6.x86 _ 64
Operating System:
CPUs: 2
Total Memory: 996.1 MiB
Name: docker1
ID: ONJP: 43QN: ARVF: E5XQ: BBPM: T6DI: XTHG: 76JB: PZEG: ELKT: HZDO: XMTZ