Easy to master Docker usage

Keywords: Operation & Maintenance Docker jenkins

preface

Docker has been very popular since 2013, many people are also interested in it, and there are many articles and learning tutorials about docker on the Internet. Here I mention "Introduction to docker" again just to sort out the previous knowledge for easy reference and sharing.
Before learning how to use Docker, we need to know about Docker:

Docker is an open source application container engine, which can easily create a lightweight, portable and self-sufficient container for any application.

In short, Docker is a software container platform. The use of each container does not interfere with each other and runs on Docker. It also means that we package our applications and all dependencies into a container (container) through Docker, which can be quickly transported to the machine for operation. It is very easy to pack and run (which is also the meaning of Docker Logo). Each application running on Docker is independent and does not affect each other. (we can use Docker technology to realize rapid deployment & rapid release of the project. We can use code hosting platform + jenkins + k8s to realize CIDI.)
  

Next, let's take a look at the installation and use of Docker.

Docker installation & Container initial operation

Docker installation and deployment

  1. Confirm that the Linux kernel version is above 3.8
~]# uname -r
  1. Install Docker
~]# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
~]# yum install -y docker-ce
  1. Initialize configuration
~]# cd /etc/
etc]# mkdir docker
~]# vim /etc/docker/daemon.json
{
  "graph": "/data/docker",
  "storage-driver": "overlay2",
  "insecure-registries": ["registry.access.redhat.com","quay.io"],
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
  "bip": "172.17.23.1/24",
  "exec-opts": ["native.cgroupdriver=systemd"],
  "live-restore": true
}
# Introduction to daemon.json configuration

# Precautions for configuration items:
# graph: this keyword will be discarded in the future and can be replaced by "data root"
# Storage driver: storage driver, that is, hierarchical file system
# Secure registers: unsafe docker registers, that is, push and pull images using http protocol
# Registry mirrors: generally, Alibaba, Netease cloud and docker China can be used as acceleration sites( https://registry.docker-cn.com )Address of
# bip: specify the docker bridge address (cannot end with. 0). 172.xx.yy.1/24 is recommended in production, where xx.yy is the last four digits of the host ip, which is convenient for locating problems
# If startup fails, check the / var/log/message log for troubleshooting
  1. Create Docker data storage directory
~]# mkdir -p /data/docker
  1. Start Docker
~]# systemctl start docker && systemctl enable docker
  1. Confirm the configured Docker bridge address
~]# ip addr show dev docker0
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:e4:3d:98:db brd ff:ff:ff:ff:ff:ff
    inet 172.17.23.1/24 brd 172.17.23.255 scope global docker0
       valid_lft forever preferred_lft forever
  1. View 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:24 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.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Try running the docker container together

  • Run the Hello word image provided by the official docker warehouse:
~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
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/

There are four steps in the container startup process:

  • The Docker client contacts the Docker server.
  • The Docker server pulls the "Hello world" image from the Docker center.
  • The Docker server (using the newly pulled image) creates a new container, which runs the executable file (script) to generate the output you currently read.
  • The Docker server pushes the information flow to the Docker client, which displays it on your terminal.

Composition of Docker

Before further studying the use of Docker, it is necessary to understand the composition of Docker.

  • Operate docker client to manage local images and containers.
  • We can build our application into an image, and using the image mentioned here (which can be considered as a running template), we run multiple identical applications. The constructed image can be push ed to the docker warehouse or our own private warehouse.
  • After using Docker to pull the image, we can use the image to run multiple containers.

Image management of Docker

TODO to be improved

reference material

Posted by neoboffins on Mon, 20 Sep 2021 00:35:45 -0700