1 introduction

I believe many of you have heard this sentence:

Human nature is a repeater.

In software development, too, we’re always looking for better ways to replicate good logic or systems. The core method is to extract common logic and components, and interface or configure differentiated things to achieve the effect of reuse. Java’s Build Once, Run Everywhere, and Spring’s powerful abstraction capabilities. This is reuse at the application level, whereas Docker works at the system level, allowing us to quickly copy a system (like CentOS) or a service (like Kafka).

2. Convenience and advantages of Docker

With Docker, we can quickly release a complete system or component using images that others have already built. It provides at least the following convenience:

  • Provide a consistent operating environment. Create containers from the same image file in the same application running environment. Ensure that the development environment, test environment, and production environment are the same. This can reduce many of the problems caused by environment differences and configuration differences. Testing bugs, and developers can no longer respond in the first place: is your environment mismatched? You can’t use it, can you?
  • Resilient system. Due to theDockerCan quickly start/stop, so that the system can dynamically change the number of services running according to the amount of requests/data, to provide scalable and variable system services.
  • Microservices development. Containers can be very lightweight and can be quickly started and stopped dynamically, making them ideal for microservices architectures. A single physical machine can run multiple containers, not necessarily a physical cluster.

To copy a system, we can add a physical machine, or run multiple systems through virtual machine technology, and now with Docker, we can boot a system. Compared with other methods, Docker has the following advantages:

  • Fast start speed, second start speed;

  • Good performance, similar to the physical machine performance, there will be too much resource loss and performance waste;

  • Small size, image can be made smaller (MB level), not like a few GB virtual machine;

  • Cross-platform, can run on Linux/Unix/Mac/Windows;

  • Good at CI/CD, mature technical practice;

  • Active community, big company endorsement, wide range of applications, mirroring resources.

3 Core Concepts of Docker

3.1 mirror Image

Speaking of mirror image, I can’t help but think of the days when I was tinkering with various systems with a U disk. At that time will find a variety of systems iso files, download speed is particularly slow, a few GB of files. Those ISO files are mirror files. But these images are relative to physical machine systems or virtual machine technologies, not Docker images.

For Docker, images are centrally managed and stored in a specific local place. Different system locations are different. Generally speaking, there is no need to manage image files themselves. Docker manages and organizes them effectively. All mirroring commands are listed as follows:

Docker Images or Docker Image lsCopy the code

Docker starts the container from an image, just as it starts the system from an ISO file installation. Images are universal and therefore shareable. Generally we can improve development efficiency by reusing good images that others have made. We just need to do custom development based on someone else’s image. For example, we can pull a Linux image with JDK, and then add our own Java application to it to form our own image.

In order to improve the reuse rate and speed, we layered the image, as shown below:

If image B is packaged based on image A, image B has one more layer than image A. Image B contains all layers of image A. The advantage of this is that instead of managing a large image, you manage hierarchy changes. If the host has downloaded the image E, then the host already has (A, B, C, E) and no longer needs to pull (A, B) when it needs to pull F. This takes advantage of Docker’s caching technology, which is also used when building new images.

For an image source name, there can be multiple tags, for example, REDis :5.0.8 and REDis :latest. 5.0.8 and Latest are both label names and latest is used by default.

3.2 Container, the Container

Now that you have the image, you can create the container. Starting a container, which is as fast as starting a process, can be started with the docker run command as follows:

$ docker run hello-world

Hello from Docker!
This message shows that 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 that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/Copy the code

A container provides a software and hardware environment that consumes physical machine resources, but it also has state and is isolated from each other. You can start multiple containers from an image, such as Ubuntu systems from an Ubuntu image. The docker ps command can be used to view the current running containers. Stopped containers are not displayed. The container file does not disappear when the container is stopped. You can view all containers with Docker ps -a.

It is easy to understand the relationship between images and containers:

The image is the template of the container. It is a file that does not run and has no state. Containers are running, stateful, isolated services. One image can start multiple containers, and one image can be created from one container, but this does not mean that the two are reversible conversions.

3.3 warehouse Repository

A warehouse is easy to understand. It is a place to store images. Since images are universal and can be shared, there needs to be a shared place, and the repository takes on that responsibility. It’s the same with Maven, NPM, etc. The largest and most commonly used warehouse is of course the official warehouse Docker Hub, but the domestic access speed is also quite touching, you can solve this problem by using domestic warehouses, such as alibaba’s warehouse. This is similar to GitHub and Maven.

We can pull other people’s images from the repository, and we can push our own images to the repository.

4 summarizes

This time mainly explainsDockerConcepts, practices and commands will be covered later.

Visit pumpkin Talk www.pkslow.com for more exciting articles!

Welcome to pay attention to the wechat public number “Pumpkin slow Talk”, will continue to update for you…

Read more and share more; Write more. Organize more.