preface

Docker and Kubernetes are the contents I have been learning recently, which was originally the goal of last year. Due to my busy work, I have no time to learn them. In the remaining six months of this year, I will systematically study relevant contents, and finally study Devops related concepts, hoping to form my own set of thoughts at last.

Docker series:
  • Why learn Docker

Basic components of Docker

Mirror Image (Image)

A Docker image is a special file system that contains the resources and environment needed by the program to run. The image does not contain any dynamic data and its contents are not changed after the build. Images are templates, which can be used to create Docker containers. In addition, Docker provides a very simple mechanism to create images and update existing images. Users can also directly download the completed images from the image warehouse for direct use.

The Container (the Container)

The container is the one that runs the image, and the relationship between the image and the container is just like the class and instance in object-oriented programming. The image is a static definition, and the container is the entity of the image runtime. The container can be created, started, stopped, deleted, paused, etc. Each container is an isolated, secure platform that can be understood as a simplified version of the Linux environment (including root user permissions, mirror space, user space, and network space) and the applications running within it.

Warehouse (Repository)

Warehouse is the place to store image, warehouses and contains multiple images, each image has different labels, used to distinguish different versions of mirror, the warehouse is divided into two kinds, public and private warehouse, one of the largest public warehouse is Docker Hub, to store a large number of mirror for users to download, here is the concept of warehouse is similar to Git, Registry can be understood as a hosting service like Github.

The relationship among the three is as follows:
  1. Create containers based on images, or create images based on containers;
  2. Pull an image from the repository, or push a local image to the repository.

How does Docker work

Docker is a client-server structure, Docker daemon runs on the host, the Client and Dcoker access through Socket, the daemon receives the Client command and manages the container running the host, the container is a running environment, is our container;

Basic Docker commands

Basic commands

Docker info Obtains docker system configuration information. Docker version Obtain the docker version. Docker help Obtain the docker help file.

The mirror command

Docker Images to view information about images:

  • -a Displays all mirrors.
  • -q Displays the container ID.

Docker Search searches for container information

  • -filter=STARS=3000;

Docker pull downloads the image, using a hierarchical download, using a federated file system, default is the new version

  • Dcoker pull mysql:5.7 Dcoker pull Image name: version number (Tag);

Docker RMI delete image

  • Docker Rmi-f Image ID
  • Docker rmi-f $(docker iamges-aq) delete all image ids
Container order

Docker run is the most core command in Docker, used to create and start containers

  • -name=” name “Container name;
  • -d Indicates the background interaction mode.
  • -it uses interactive mode to enter the container.
  • -p Is used to expose the port of the container to the port of the host in the format of hostPort:containerPort. By exposing the port, external hosts can access applications in the container.
  • -p Randomly specifies the port.
  • -c is used to assign CPU shares to all processes running in the container. This is a relative weight. The actual processing speed depends on the CPU of the host
  • -m Limits the total memory allocated to all processes in a container. The unit is B, K, M, or G.

Docker PS lists running containers

  • -a Lists the current running containers and containers that have been run in the past.
  • -n=? Displays the recently created container;
  • -q Displays only the container number.

Out of the container

  • Exit The container stops and exits;
  • Ctrl + P + Q Stops the container and exits;

Remove the container

  • Docker rm container ID delete the specified container, cannot delete the running container;
  • Docker ps – a – q | xargs docker rm to delete all the container;

Start and stop container operations

  • Docker start container id Start container id;
  • Docker restart container id Restart container id.
  • Docker stop container id Stop container id;
  • Docker kill container ID Strong kill container;

Docker logs View the logs of docker logs

  • –details Displays log details.
  • -f Displays following the log output.
  • –tail Displays data for the specified row starting at the end;
  • -t Displays the timestamp.
  • –since since;
  • — Until the end;

Docker top Displays the process information of the container

Docker inspect to view metadata of the image

Enter the running container

  • Docker execit container id;
  • Docker attach container Id;

The container copies files to the host

Docker cp Container Id Container path Host path;

The end of the

Welcome everyone little attention, little praise!