The design concept of Docker is to Build, Ship and Run Any App Anywhere. It is written in the Go language. It wants to manage the lifecycle of packaging, distributing, deploying, and running Application components so that the final Application can run smoothly on any machine.

Docker is like a cargo ship: it loads apps and the environmental configurations they depend on into individual containers, and then tranships those containers safely to another location.

Basic and use parts

  1. Linux related commands and background knowledge.

  2. Basic knowledge of Maven/Git etc.

๐ŸŒDocker official website: click here to enter

Why do you need Docker?

The development and deployment environments of a production (code) are often different. These may include differences in the operating system, runtime environment, or application configuration. These differences are likely to cause problems in the deployment environment when code that works well in the development environment.

Especially, with the continuous iteration of the version, the running environment is more and more complex, the communication cost between the developer and the operation and maintenance personnel will be higher and higher.

Can there be a way for developers to package the environment where the code runs (configuration/data/parameters, etc.) into the deployment environment when they deliver the code?

Docker was born to solve this problem. It provides a standardized solution for this and has grown rapidly since its inception in 2014.

Once upon a time, the code was the application. Developers simply compile the program and submit it to O&M, who then deploys it. After learning Docker, I will not just simply submit the code, but put the running documents, configuration environment, running environment, running dependency packages and so on into a container and deliver them to operation and maintenance (cloud platform).

We are going to deploy the application in a clustered environment

Due to the brutal growth of the Internet, today’s network applications have adopted a distributed cluster to cope with such high concurrent requests.

In other words, if the application is deployed in the traditional way, the operation and maintenance staff may have to manually configure the installation environment for each distributed node, which can be costly in manpower and time.

For example, if the distributed cluster is to be expanded flexibly again, o&M will have to install MySQL, JDK, Hadoop, and ZooKeeper on new machines, not counting the cost of configuring these environments.

So the designers of Docker wanted to do such a thing: package their code + configuration + environment into an image, and then directly migrate the whole image to another running machine.

This is consistent with the philosophy of the JVM virtual machine: compile once, run everywhere.

You just need a mirror image

Assuming that an App needs to rely on Redis, MongoDB and MySQL to run normally, the operation and maintenance personnel need to manually install Redis, MongoDB and MySQL in the deployment environment according to the development manual provided by the developers using the traditional method. Also consider the differences between versions (such as MySQL5.7 and MySQL8.0).

After using Docker, these tools can be directly packaged into an image file. The operation and maintenance only need to run the image in Docker to obtain the exact same deployment environment.

To summarize Docker

Docker is a container virtualization technology that solves the problems of running environment and configuration, facilitates continuous inheritance and contributes to the overall release.

Docker brings the following conveniences:

  • Faster application delivery and deployment.
  • Easier upgrade and capacity expansion/reduction.
  • Lower the threshold of system operation and maintenance.
  • Efficient computing resource utilization.
  • Build once, run anywhere.

Briefly learn about two types of virtual technologies

Virtual machine technology

Surely we know or use the well-known VM Ware (or something similar). We can use this tool to run A Linux, a Unix system on a Windows system, and programs running in a virtual machine will be unaware of it.

For us, the virtual machine and all its internal applications, the configuration is just a common image file. You can delete the whole thing when you don’t need it. And when the environment in the virtual machine changes, it has no effect on our real physical machine.

Of course, the virtual machine also emulates hardware devices such as memory, processors, hard disks, and network adapters. It simulates the entire operating system. This makes virtual machines have their own limitations: high resource usage, many redundant steps, and slow startup.

Virtual container technology

For these reasons, Linux later developed another virtualization technique: Linux Containers (abbreviated LXC). It is not a complete operating system, but it retains the Linux operating environment and supports isolation of processes that are run by different applications.

portable

In addition, each container is isolated from each other. Each container has its own file system, and processes between containers do not affect each other.

Docker uses Linux as the kernel, so what about Windows users? Unfortunately, Windows first requires you to install a Linux virtual environment (if your Windows is non-professional or flagship) before you can run Docker. It’s a little more cumbersome to use than it is on Linux. But don’t lose heart, because at least at home, we basically all choose Linux kernel server OS.

If you want to learn how to use Docker in Windows environment, you need to use VM Ware to simulate a Linux virtual machine, and learn to use Docker in this virtual machine. Don’t forget to configure network Settings for the virtual machine, as we will use yum or Docker pull commands to download files from the Internet on the virtual machine.

๐ŸŒ Reference link: Comparison of dedicated machines, VMS, and containers

Docker container framework

Docker is based on C/S architecture. The Docker Daemon process is responsible for building, distributing, and running the Docker container.

Clients and daemons communicate through sockets, or RESTful apis.

The three elements of Docker

Mirror image (image)

A Docker image is a read-only template. Just as we can create multiple virtual machines from a single ISO file, we can create multiple containers from the same template.

The container (the container)

A container is a running instance created by an image. It can be started, stopped, or even deleted. Each container is an isolated and secure platform. Think of the container as a simple Linux environment (root permissions, process space, network space, etc.) and the applications that run in it.

๐ŸŒ Reference links: More on containers and images

Warehouse (repository)

Just like the GitHub repository where code/projects are managed, Docker images are managed centrally in a central repository. The largest public repository is Docker Hub. Permissions can be classified into Private and Public.

Docker Hub

We probably know more about GitHub than Docker Hub: we store our work/apps in the cloud, so we can clone them on any machine we want.

The work of Docker Hub is actually similar: developers can also store their own configuration + Docker image packaged by the application to the cloud, and operation and maintenance personnel can directly obtain the Docker image in the cloud and deploy it.

๐ŸŒDocker Hub official website: click here to enter

For Domestic developers

Due to network restrictions, Chinese developers generally choose Ali Cloud, netease Cloud and other cloud warehouses. However, we are more inclined to the former, so the author after the article is all ali Cloud for the platform to operate.

Install Docker under CentOS 7

Currently, Linux supports Docker only in the kernel of a release.

Docker runs on CentOS 7 and requires a 64-bit system with a kernel version of 3.10 or higher.

If Docker is running on CentOS 6.5 or later, it requires a 64-bit system with a kernel version of 2.6.32-431 or later.

Docker website installation tutorial: click here to enter

I installed Docker in centOS 7 environment. Even in centOS 6.8, the steps for installing Docker may be different.

Run the uname command to view the kernel version of the CentOS system.

$ uname -r
Copy the code

Check the release file:

$ cat /etc/redhat-release
Copy the code

Use yum to install GCC dependencies (check whether the network is connected to the VM) :

$ yum -y install gcc
$ yum -y install gcc-c++
Copy the code

If the original system has older versions of the Docker engine, copy the following command to remove them:

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
Copy the code

No docker-related dependencies are currently installed on the machine, or they will be uninstalled.

We then used the yum command to install the Docker-CE version. The website gives the following tips:

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

If you install the Docker engine on a new machine, you first need to configure the Docker repository, and then you can install or update Docker in this repository.

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
Copy the code

Note โ— : The download.docker.com warehouse provided in the official website is very slow in China, so the following stable image warehouse needs to be configured as the Aliyun warehouse. Of course, you could have done it directly in the –add-repo argument in the previous step.

$ yum-config-manager --add-repo \
	http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code

The system displays a message indicating that the configuration information is configured in /etc/yum.repos. D /docker-ce.

Update the index of yum software package.

$ yum makecache fast
Copy the code

If you install the Docker-CE version of yum, you can add the -y parameter to skip all queries (install all), and then you need to wait a while.

$ yum -y install docker-ce
Copy the code

Finally, launch docker-CE and we’re ready to use it!

$ systemctl start docker
Copy the code

Check whether the Docker installation is successful by using the version parameter:

$ docker version
Copy the code

Use Ali Cloud to configure image acceleration

Log in aliyun, choose to register a new account, or choose to reuse taobao account. Search in services: Container mirror services, select mirror accelerator. At the end of our Docker topic, when we learn how to upload our images to a remote warehouse, we will also use Aliyun’s container image service.

Mirror accelerator

$ mkdir -p/etc/docker
$ vim /etc/docker/daemon.json
Copy the code

Set accelerator address in JSON file, save and exit:

{
  "registry-mirrors": ["This value is based on your accelerator address."]}Copy the code

Reload the configuration file and start:

$ systemctl daemon-reload
$ systemctl restart docker
Copy the code

Check to see if Docker has been started in the process:

ps -ef | grep docker
Copy the code

๐ŸŒ Aliyun home page: click here to log in

Download a Hello-world image

By convention, we start a helloWorld instance after the first Docker installation.

$ docker run hello-world
Copy the code

Unable to find image ‘hello-world:latest’ locally But don’t worry, because the Docker engine will search locally for the image first. Docker downloads the Hello-World image from the remote repository only when it cannot be found locally. Latest is a TAB that downloads the latest version of the Hello-World mirror.

Eventually, Docker downloads the image from the Aliyun repository, creates a container from it, and runs it.

If the following information is displayed, the installation is successful:

Hello from Docker!
This message shows that your installation appears to be working correctly.
Copy the code