It was the third day of my August challenge

Docker learning a

What is the Docker

Address: hub.docker.com/

Docker encapsulates and isolates processes, which is a virtualization technology at the operating system level

Because an isolated process is independent of the host and other isolated processes, it is also called a container

Application scenarios of Docker

  • Automated testing and continuous integration, release
  • Automated packaging and publishing of Web applications
  • Background applications are easy to deploy

The advantage of the docker

  • Fast, consistent delivery of applications
  • Portable, scalable
  • Light, fast, economical, efficient, presslinuxIts own resources

What can Docker do?

First, what’s the difference between Docker and virtual machines

The previous virtual machine, the system occupies large resources, many steps are redundant, and the startup is slow, can not endure

This is what Docker looks like today,

Containers are isolated from each other, complement each other, and run together on the same operating system to maximize the use of operating system resources

What’s the difference between Docker and virtual machine technology?

  • Each container is isolated from each other. They have their own file system and do not affect each other
  • The container does not have its own kernel, it does not have its own hardware, and its applications run directly in the host kernel
  • A traditional virtual machine is a virtual piece of hardware, running a complete operating system, and running applications on it

So what exactly can Docker do?

Do the conversation

There are several improvements to DevOps:

  • Applications can be deployed and delivered more quickly

The previous troublesome installation steps are gone. After using the Docker container, the image is packaged and published for testing, one-click deployment and running

  • It can be upgraded and expanded more easily

Docker is used to package the project into an image, which is easy to upgrade and expand

  • It’s easier to develop, operate, and test

No more worrying about inconsistencies between development environment, test environment, and operation environment

  • Use resources more efficiently

Dcoker runs in the kernel of the host, and multiple Instances of Docker can be deployed on this physical host

The composition of the Docker

Docker uses a client-server (C/S) architectural pattern that uses remote apis to manage and create Docker containers

Docker has three basic concepts:

This is from the Internet

  • The mirror

It is a root file system, similar to a template, which is static

  • The container

Like an instance pulled out of a template, the container is created using an image that can be created, started, stopped, paused, deleted, and so on

  • warehouse

Where the image is stored, you can think of it as a code control center

Install and use Docker

The installation

There are several ways to install Docker on the network:

  • The official script is automatically installed
  • Install using the Docker repository
  • Install using the ==shell== script

Let’s take the Ubuntu system as an example and install it in the way of Docker warehouse. My Ubuntu system version is as follows:

# cat /etc/os-release NAME="Ubuntu" VERSION=" 18.04.5lts (Bionic Beaver)" ID= Ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu" 18.04.5lts "VERSION_ID="18.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=bionic UBUNTU_CODENAME=bionicCopy the code

Set up the warehouse

Installing dependency Packages

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
Copy the code

Add Docker’s official GPG key:

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
Copy the code

Authentication key, can directly search 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 following the 8 characters

sudo apt-key fingerprint 0EBFCD88
Copy the code

The following output has the secret key set correctly

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <[email protected]>
sub   rsa4096 2017-02-22 [S]
Copy the code

Set up the stable version repository

sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
  $(lsb_release -cs) \
  stable"
Copy the code

Install the Docker

Install the latest Docker version

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Copy the code

After the installation is complete, check whether the installation is OK

You can view the docker version through Docker Version

# Docker Version Client: Docker Engine - Community version: 20.10.7 API version: 1.41 Go version: go1.13.15 Git commit: f0df350 Built: Wed Jun 2 11:56:40 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine-Community Engine: Version: 20.10.7 API Version: 1.41 (minimum Version 1.12) Go Version: Go1.13.15 Git commit: b0f5bc3 Built: Wed Jun 2 11:54:48 2021 OS/Arch: Linux/AMd64 Experimental: false Containerd: Version: 1.4.8 GitCommit: 7 eba5930496d9bbe375fdf71603e610ad737d2b2 runc: Version: 1.0.0 GitCommit: V1.0.0-0-g84113ee docker-init: Version: 0.19.0 GitCommit: DE40AD0Copy the code

Run a hello-world

sudo docker run hello-world
Copy the code

If the following information is displayed, docker is successfully installed

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest

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

Of course, you can also choose not to install the latest version, install your own version can also be

  1. Use ==apt-cache Madison docker-ce== to see which versions are available in the repository

  2. Use ==sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd. IO == to install the specified version of Docker

  3. Use ==sudo docker run hello-world== to verify that the installation is successful

  • View the Docker image
Docker images REPOSITORY TAG IMAGE ID CREATED SIZE Hello -world Latest d1165f221234 4 months ago 13.3kBCopy the code
  • Docker mirror
Sudo apt-get purge docker-ce docker-ce-cli containerd. IO Delete the /var/lib/docker installation directory sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerdCopy the code

Mirror to accelerate

If you are using ali cloud server partners can see this step

To configure image acceleration, the installation version of Docker needs to be above 1.10.0. Our current docker version is 1.41, which is fully compliant

We can use the accelerator by modifying the daemon configuration file /etc/docker/daemon.json to execute the following command

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://uhr5ub75.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code

Docker Run process

  • Docker run now finds the corresponding image locally and runs it directly if there is one
  • If not, download it from Docker Hub. If yes, download it to local and run it
  • If not, it will report an error

The underlying principles of Docker

How does Docker work?

Docker is a C/S model. The background daemon of Docker runs on the host, and the client and server communicate with each other through Socket

When the Docker server receives the instruction from the Docker client, it executes the instruction

Why is Docker faster than a virtual machine?

On the network to find a picture, let’s contrast it is clear

As shown in the figure, Docker is faster than virtual machine for the following reasons:

  • Docker has fewer layers of abstraction than virtual machines
  • Docker uses the kernel of the host machine, while virtual machines need to create an OS

Based on the preceding two points, the VM starts with the OS loaded, which takes minutes to start

When docker starts, it does not need to load the operating system kernel, so it is fast and the time is basically second level

References:

docker docs

Welcome to like, follow and collect

Dear friends, your support and encouragement are the motivation for me to keep sharing and improve the quality

All right, that’s it for this time

Technology is open, our mentality, should be more open. Embrace change, live in the sun, and strive to move forward.

I am nezha, welcome to like the collection, see you next time ~