This is the third day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Docker is an open source application container engine, which is based on Go language and complies with Apache2.0 protocol. Docker allows developers to package their applications and dependencies into a lightweight, portable container that can then be published on any popular Linux machine. It can also be virtualized. The containers are completely sandboked, there is no interface to each other (similar to aN iPhone app), and more importantly, the performance overhead of the containers is extremely low.

Application scenarios

  • Automated packaging and publishing of Web applications.
  • Automated testing and continuous integration, release.
  • Deploy and tune databases or other backend applications in a service-oriented environment.
  • Build your OWN PaaS environment by building from scratch or extending existing OpenShift or Cloud Foundry platforms

The advantage of the Docker

Deliver your application quickly and consistently

Docker simplifies the development lifecycle by allowing developers to work in a standardized environment using a native container for the application or service you provide. Containers are ideal for continuous integration and continuous delivery (CI/CD) workflows. Consider the following example scenario:

  • Your developers write code locally and share their work with colleagues using the Docker container.
  • They use Docker to push their apps into a test environment and perform automated or manual tests.
  • When developers find errors, they can fix them in the development environment and then redeploy them to the test environment for testing and validation.
  • When testing is complete, push the patch to production as easily as push an updated image to production.

Responsive deployment and scaling

Docker is a container-based platform that allows for highly portable workloads. Docker containers can run on developers’ home machines, physical or virtual machines in data centers, on cloud services, or in mixed environments.

Docker’s portability and lightweight features also make it easy for you to accomplish dynamically managed workloads and extend or dismantle applications and services in real time as business needs indicate.

Running more workloads on the same hardware

Docker is light and fast. It provides a viable, cost-effective, and efficient alternative to hyperviser-based virtual machines, so you can leverage more computing power to achieve business goals. Docker is ideal for high-density environments as well as small to medium sized deployments, where you can do more with less resources.

The basic components of Docker

The basic components of Docker are as follows

  • Image: Docker Image, which is a root file system. For example, the official image Ubuntu :16.04 contains the complete root file system of the Ubuntu16.04 minimum system.
  • Container: The relationship between an Image and a Container is similar to that between classes and instances in object-oriented programming. The Image is a static definition and the Container is the entity that the Image runs on. Containers can be created, started, stopped, deleted, or paused.
  • Repository: A Repository can be viewed as a code control center where images are stored.

Docker installation (MAC)

Homebrew is installed

brew install --cask --appdir=/Applications docker
Copy the code

Check the installation after completion

➜ ~ docker -- Version Docker version 20.10.6, build 370c289Copy the code

Mirror to accelerate

Aliyun’s accelerator is used here, visit cr.console.aliyun.com/cn-hangzhou… , and then click on the mirror accelerator, you will see the following information

After the installation is complete, run the following command to view information similar to the following

! [image-20210811204738636](/Users/chenbang/Library/Application Support/typora-user-images/image-20210811204738636.png)

The installation operations for other environments are similar, and you can Google it by yourself

Docker common commands

Basic commands

Docker system information, including the number of images and containers docker command --help # Help command (optional parameters can be seen)Copy the code

Command help document address: docs.docker.com/engine/refe…

The mirror command

Look at mirror

Docker images View all images on the local host

-a/–all Lists all images

-q/–quiet Displays only the ID of the image

$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       centos7   8652b9f0cb4c   9 months ago   204MB
Copy the code
  • REPOSITORY REPOSITORY source of the image

  • TAG Image TAG

  • IMAGE ID ID of an IMAGE

  • CREATED Indicates the creation time of the image

  • SIZE Mirror SIZE

Image search

docker search

$ docker search redisNAME DESCRIPTION STARS OFFICIAL AUTOMATED Redis Redis is an open source key-value store that... 9782 [OK] Sameersbn/Redis 83 [OK] Grokzen/Redis -cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.78 Rediscommander/Redisis-Commander Alpine Image for Redisis-commander-Redis man... 6.78 Rediscommander/Redisis-Commander Alpine Image for Redisis-commander-Redis man... 64 [OK] Redislabs/Redisearch Redis With the RedisSearch Module pre-loaded... 37 kubeguide/redis-master redis-master with "Hello World!" 33 redislabs/redisinsight RedisInsight - The GUI for Redis 33 redislabs/redis Clustered in-memory database engine Compatib... 31 Oliver006 / Redis_Vendor Prometheus Vendor for Redis Metrics... 28 Redislabs/Rejson Redisjson-Enhanced JSON Data Type Processi... Arm32v7 / Redis Redis is an open source key-value store that... 24 redislabs/redisgraph A graph database module for Redis 15 [OK] redislabs/redismod An automated build of redismod - Latest Redi... 15 [OK] Arm64V8 / Redis Redis is an open source key-value store that... 14 redislabs/rebloom A probablistic datatypes module for Redis 13 [OK] webhippie/redis Docker images for Redis 11 [OK] Insready/Redis-stat Docker image for the real-time Redis monitor... 10 [OK] s7anley/redis-sentinel-docker Redis Sentinel 10 [OK] goodsmileduck/redis-cli redis-cli on alpine 9 [OK] redislabs/redistimeseries A time series database module for Redis 9 centos/redis-32-centos7 Redis in-memory data Structure store, informs the a... 5 ClearLinux/Redis Redis key-value data Structure server with t... 3 wodby/redis Redis container image with orchestration 1 [OK] tiredofit/redis Redis Server w/ Zabbix monitoring and S6 Ove... 1 [OK] xetamus/redis-resource forked redis-resource 0 [OK]Copy the code

The extension command

$ docker search mysql --filter=stars=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, The open - source base... 11258 [OK] Mariadb Mariadb Server is a performing center... 4277 [OK]Copy the code

Find images with stars greater than 3000

$ docker search mysql --filter=stars=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, The open - source base... 11258 [OK] Mariadb Mariadb Server is a performing center... 4277 [OK]Copy the code

Image download

Docker pull image name [:tag]

$ docker pull mysqlUsing default tag: latest # Pulling from library/mysql Pull complete 1a2b594783f5: Pull complete b30e406dd925: Pull complete 48901e306e4c: Pull complete 603d2b7147fd: Pull complete 802aa684c1c4: Pull complete 715d3c143a06: Pull complete 6978e1b7a511: Pull complete f0d78b0ac1be: Pull complete 35a94d251ed1: Pull complete 36f75719b1a9: Pull complete Digest: sha256:8b928a5117cf5c2238c7a09cd28c2e801ac98f91c3f8203a8938ae51f14700fd Status: Downloaded newer image for mysql: latest docker. IO/library/mysql: download the latest # source real address # docker pull mysql equivalent to the docker pull # docker.io/library/mysql:latestCopy the code

You can specify a version download like docker pull mysql:5.7

Remove the mirror

[root@iZwz99sm8v95sckz8bd2c4Z ~]# docker Rmi-f image ID #2 Delete multiple images ID [root@iZwz99sm8v95sckz8bd2c4Z ~]# Docker Rmi-f image ID Image ID Image ID #3. [root@iZwz99sm8v95sckz8bd2c4Z ~]# docker rmi-f $(docker images-aq)Copy the code

Container order

Pull out a container

docker pull centos
Copy the code

Run the container

Docker run [Optional parameter] image # Parameter Description --name=" name "specify the name of the container -d Run in background mode -it run in interactive mode, enter the container to view the contents -p Specify the container port (-p IP: host port: container port -p Host port: container port -p Container port) -p Randomly specified port (capital P)Copy the code

Into the container

docker exec -it f42ae22e4b72 bash
Copy the code

Remove the container

Docker start Container ID # Start container ID # Restart container ID # Restart container ID docker Stop container ID # Stop the current container Docker kill container ID # Forcibly stop the current containerCopy the code

Other Common Commands

The log view

Docker logs -tf container ID docker logs --tail number Container ID #num specifies the number of logs to be displayedCopy the code

Check the process

$ docker top f42ae22e4b72
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                3242                3215                0                   16:17               ?                   00:00:00            /bin/bash
root                3304                3215                0                   16:20               ?                   00:00:00            bash
Copy the code

Viewing metadata

Docker INSPECT Container IDCopy the code

The following figure summarizes the commands