What is docker?
Docker is an [open source] (https://baike.baidu.com/item/%E5%BC%80%E6%BA%90/246339) application container engine that allows developers to package their applications and dependencies Packaged into a portable container and then published to any popular [Linux] (https://baike.baidu.com/item/Linux) machine, you can also implement [virtualization] (https://baike. Baidu.com/item/%E8%99%9A%E6%8B%9F%E5%8C%96). The container is completely using [sandbox] (https://baike.baidu.com/item/%E6%B2%99%E7%AE%B1/393318) mechanism, there will be no interface between each other.
## The following is only for the docker installation instructions under centos7. For other operating systems, please refer to the docker official website: docker.com
##Download and install docker
Curl -sSL https://get.daocloud.io/docker | sh
##Set the docker image pull accelerator (domestic users)
Curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://00ff2cb2.m.daocloud.io
#说明:00ff2cb2.m.daocloud.io This address is replaced by your application for daocloud
## Start the docker service and set the boot
Systemctl enable docker.service && service docker start
- View the
dockerversion using the
[root@localhost ~]# docker version
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:41:23 2017
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:49 2017
- Simply pull and run the
nginximage to get a taste of docker’s charm:
# 1. Pull the nginx image
[root@localhost ~]# docker pull nginx
Using default tag: latest
Latest: Pulling from library/nginx
E7bb522d92ff: Pull complete
6edc05228666: Pull complete
Cd866a17e81f: Pull complete
Status: Downloaded newer image for nginx:latest
# 2. Run the nginx image
[root@localhost ~]# docker run -d --name mynginx -p 8080:80 nginx
# 3. Access the nginx server
[root@localhost ~]# curl localhost:8080
<title>Welcome to nginx!</title>
Margin: 0 auto;
Font-family: Tahoma, Verdana, Arial, sans-serif;
<p>If you see this page, the nginx web server is successfully installed and
Working. Further configuration is required.</p>
<p>For online documentation and support please refer to
Commercial support is available at
<p><em>Thank you for using nginx.</em></p>
First of all, congratulations on the successful operation of the
docker container! Before really getting into docker, let’s take a look at some of the concepts of
We all know that the operating system is divided into kernel and user space. For Linux, after the kernel is booted, the
root filesystem is mounted to provide user space support. The Docker image is equivalent to a
root filesystem. For example, the official image
ubuntu:16.04 contains a complete set of Ubuntu 16.04 minimal system
root file system.
Docker image is a special file system, in addition to providing the program, library, resource, configuration and other files required by the container to run, it also contains some configuration parameters (such as anonymous volume, environment variables, users, etc.) prepared for the runtime. ). The image does not contain any dynamic data and its content will not be changed after it is built.
The relationship between the image (
Image) and the container (
Container) is like the
instance in object-oriented programming. The mirror is a static definition, and the container is the entity of the mirror runtime. Containers can be created, started, stopped, deleted, paused, and more.
The essence of a container is a process, but unlike a process that is executed directly by the host, the container process runs on its own separate [namespace] (https://en.wikipedia.org/wiki/Linux_namespaces). So the container can have its own
root filesystem, its own network configuration, its own process space, and even its own user ID space. The processes inside the container are run in an isolated environment and are used as if they were operating under a host-independent system. This feature makes container-packaged applications more secure than running directly on the host. Because of this isolation, many people often confuse containers and virtual machines when they first learn Docker.
As mentioned earlier, mirroring uses tiered storage, as is the container. Each container runtime is a mirror-based layer on which to create a storage layer of the current container. We can call this storage layer for the container runtime read and write as the container storage layer**.
The container storage layer has the same life cycle as the container. When the container dies, the container storage layer also dies. Therefore, any information stored in the container’s storage tier will be lost as the container is deleted.
As required by Docker best practices, containers should not write any data to their storage tier, and the container storage tier should remain stateless. All file write operations should use [Volume] (https://yeasy.gitbooks.io/docker_practice/content/data_management/volume.html), or bind the host directory to read at these locations. Writes skip the container storage layer and read and write directly to the host (or network storage), which is more performance and stability.
The life cycle of a data volume is independent of the container, the container dies, and the data volume does not die. Therefore, after the data volume is used, the data is not lost after the container is deleted or re-run.
Once the image is built, it can be easily run on the current host. However, if you need to use this image on other servers, we need a centralized storage and distribution service, [Docker Registry] (https:// Yeasy.gitbooks.io/docker_practice/content/repository/registry.html) is such a service.
A Docker Registry can contain multiple repositories (
Repository); each repository can contain multiple tags (
Tag); each tag corresponds to a mirror.
Typically, a repository will contain images of different versions of the same software, and tags are often used for each version of the software. We can specify which version of the software is mirrored by the format of
. If no label is given,
latest will be used as the default label.
Take [Ubuntu Mirror] (https://store.docker.com/images/ubuntu) as an example.
ubuntu is the name of the repository, which contains different version tags, such as
16.04. We can specify which version of the image is required by
ubuntu:16.04. If the tag is omitted, such as
ubuntu, it will be treated as
Warehouse names often come in the form of a two-part path, such as
jwilder/nginx-proxy, which often means the username in the Docker Registry multi-user environment, which is often the corresponding software name. But this is not absolute, depending on the software or service of the specific Docker Registry you are using.