Docker series: the first lecture. Docker Introduction and Installation

Source: Internet
Author: User
Tags nginx server docker hub docker run docker registry

What is Docker?

Docker's English translation “搬运工” means that what he's carrying is what we always say 集装箱Container , Container is an app of any kind, and our developers can use Docker to turn the app into a label, 准化的 可移植的 自管理的 component, We can develop, debug and run in any major operating system.

What is the difference between Docker and virtual machine?

Conceptually, Docker is similar to our traditional virtual machines, just more lightweight and more convenient, and the main difference between Docker and virtual machine is the following:

    • Virtualization technology relies on physical CPUs and memory, hardware-level, and our Docker is built at the operating system level, leveraging the operating system's containerized technology, so Docker can also run on virtual machines.
    • We know that the system in the virtual machine is what we often call the operating system image, more complex, and Docker is relatively lightweight, we can use Docker to deploy a separate redis, similar to the virtual machine to install a Redis application, but we use Docker Deployed applications are completely isolated.
    • We all know that traditional virtualization technology is saved by snapshots, and Docker introduces a mechanism similar to source management, which records the snapshot history of the container and the cost of switching is very low.
    • Traditional virtualization technology is very complex when building systems, and Docker can build an entire container through a simple Dockerfile file, and more importantly Dockerfile can be written manually so that application developers can publish Dockerfile To define the environment and dependencies of the application, which is advantageous for continuous delivery.
Why do you use containers?

What does the application container look like, a well-done application container grows as a virtual machine with a specific set of applications, for example, I want to use Redis now, then I'll find a container for Redis and then run it, and I'll be able to use it directly.

So why not just install a Redis? Certainly is feasible, but sometimes according to each person's computer's different, when installs the time may report various kinds of errors, in the case your machine is poisoned, your computer hangs, all your service needs to reinstall. But with Docker or a container that's different, you have a virtual machine that can run, and as long as you can run the container, the Redis configuration is saved. And if you want to change a computer, no problem, very simple, directly to the container "end" can use the service inside the container.

Docker Architecture

Docker uses the C/s (client/server) architecture, the Docker client communicates with the Docker daemon, and the Docker Daemon is responsible for building, running, and distributing Docker containers. Docker clients and Daemons can run on the same system, or you can connect Docker clients to the remote Docker daemon. The Docker client and daemon use the REST API to communicate through a UNIX socket or network interface.

  • Docker Damon: Dockerd, which listens to Docker API requests and manages Docker objects such as mirrors, containers, networks, and Volume.
  • Docker Client: Docker,docker client is the most important way to interact with Docker, for example, we can run a container through the Docker Run command, and then our client will send the command to the above Dockerd and let him do the real thing.
  • Docker Registry: A repository for Docker images, Docker hub is a public repository officially provided by Docker, and Docker looks for mirrors from Docker hub by default, and you can easily run a private warehouse when we use Docker pull or Docker Run command, we pull the mirror from our configured Docker image warehouse, and when we use the Docker push command, we push the image we build into the corresponding mirror repository.
  • Images: Mirror, mirroring is a read-only template with instructions for creating a Docker container, and in general, mirroring is based on a few additional base images and adds some extra customization capabilities. For example, you could build a Centos-based image and then install an Nginx server on top of the base image, which would make up a mirror of our own.
  • ContainersContainer, a container is a running instance of mirroring, you can use the Docker REST API or the CLI to manipulate the container, the container is essentially a process, but unlike the process that executes directly on the host, the container process runs in its own separate namespace. So the container can have its own root file system, its own network configuration, its own process space, and even its own user ID space. Processes within a container are run in an isolated environment, and are used as if they were operating under a host-independent system. This feature makes container-encapsulated applications more secure than directly running in the host.
  • 底层技术支持: Namespaces (do isolation), CGroups (resource constrained), UnionFS (mirroring and container layering) the-underlying-technology Docker underlying architecture analysis
Docker installation

Go directly to the official documentation and choose the right platform to install, for example, we want to install Docker on the CentOS system, which can be installed on the https://docs.docker.com/install/linux/docker-ce/centos/ prompt.

1. Install Dependent packages:

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

2, add the software warehouse, we use stable version of Docker here, execute the following command to add the Yum warehouse address:

$ sudo yum-config-manager     --add-repo     https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo# 官方源# $ sudo yum-config-manager #     --add-repo #     https://download.docker.com/linux/centos/docker-ce.repo

3, then direct installation can:

$ sudo yum install docker-ce

4. If you want to install the specified version, you can use the Yum list to list the available versions:

$ yum list docker-ce --showduplicates | sort -rdocker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable

5, such as here can install 18.03.0.CE version:

$ sudo yum install docker-ce-18.03.0.ce

6, to start Docker is also very simple:

$ sudo systemctl enable docker$ sudo systemctl start docker

7, another type of installation can directly download the specified software package directly installed, go to address: https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ find the appropriate .rpm包 download, and then install:

$ sudo yum install /path/to/package.rpm
Docker Accelerator

It is sometimes difficult to pull mirrors from the Docker Hub at home, so you can configure the Mirror accelerator. The official Docker and many domestic cloud service providers provide domestic accelerator services, such as:
The official Docker offers the Chinese registry mirror https://registry.docker-cn.com
Seven Qiniu accelerator https://reg-mirror.qiniu.com/

When you configure an accelerator address, if you find that the pull is not mirrored, switch to another accelerator address. All the major cloud service providers in the country provide Docker mirroring acceleration services, and we recommend that you select the corresponding mirror accelerator based on the cloud platform on which you are running Docker.

For systems that use SYSTEMD, write the following in/etc/docker/daemon.json (if the file does not exist, create a new file)

{  "registry-mirrors": [    "https://registry.docker-cn.com"  ]}

Note : Be sure that the file conforms to the JSON specification, otherwise Docker will not start.

Restart the service.

$ sudo systemctl daemon-reload$ sudo systemctl restart docker
Test if Docker is installed correctly
$ docker Run hello-worldunable to the find image ' Hello-world:latest ' locallylatest:pulling from LIBRARY/HELLO-WORLDCA4F61B1 923c:pull CompleteDigest:sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905cStatus: Downloaded newer image for Hello-world:latesthello from docker! This message shows the your installation appears to be working correctly. To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.    2. The Docker daemon pulled the "Hello-world" image from the Docker Hub. (AMD64)  3. The Docker daemon created a new container from this image which runs the executable that produces the output is Currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something + ambitious, you can run an Ubuntu container with: $ docker run-it ubuntu Bashshare images, automate Workflows, and more with a free Docker id:https://cloud.docker.com/for more examPles and ideas, visit:https://docs.docker.com/engine/userguide/ 

If you can output the above information correctly, the installation is successful.

Adding kernel parameters

In the default configuration, if you use Docker CE in CentOS, you see these warning messages:

WARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is disabled

Please add kernel configuration parameters to enable these features.

$ sudo tee -a /etc/sysctl.conf <<-EOFnet.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1EOF

Then reload sysctl.conf to

$ sudo sysctl -p

Docker series: the first lecture. Docker Introduction and Installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.