Docker notes 1-basic concepts

Architecture

  • Image: Docker image is equivalent to a root file system. For example, the official mirror ubuntu:16.04 contains a complete set of the root file system of the Ubuntu 16.04 minimal system.
  • Container: The relationship between the image and the container is like the class and instance in object-oriented programming. The image is a static definition, and the container is the entity of the image at runtime. Containers can be created, started, stopped, deleted, suspended, etc.
  • Repository: The repository can be regarded as a code control center for storing images.

Docker uses a client-server (C/S) architecture model and uses remote APIs to manage and create Docker containers

  • Docker host: a physical or virtual machine used to execute Docker daemons and containers

  • Docker Registry: Docker warehouse is used to save images, which can be understood as a code warehouse in code control.
    A Docker Registry can contain multiple repositories (Repository); each repository can contain multiple tags (Tag); each tag corresponds to a mirror .
    Usually, a warehouse will contain images of different versions of the same software, and tags are often used to correspond to each version of the software. The format of <warehouse name>:<tag> can be used to specify which version of the software is the mirror image. If no label is given, latest will be used as the default label.

  • Docker Machine: is a command-line tool that simplifies the installation of Docker. You can install Docker on the corresponding platforms through a simple command line, such as VirtualBox, Digital Ocean, and Microsoft Azure.

Mirror image

Mirror is a lightweight, executable, independent software package used to package the software operating environment and software developed based on the operating environment. It contains all the content needed to run a certain software, including code, runtime, library, and environment Variables and configuration files.

Mirror loading principle

unionfs

unionfs: The union file system is a hierarchical, lightweight and high-performance file system. It supports the modification of the file system as a single submission to layer by layer. At the same time, different directories can be mounted to the same virtual file system. The
union file system is the basis of Docker mirroring. Mirroring is inherited through layers, and various specific application mirrorings are made based on the basic mirroring

Mirror loading principle

Bootfs (boot fie system) mainly includes bootloader and kernel. Bootloader is mainly boot loading kernel. LInux will load the bootfs file system when it starts. The bottom layer of Docker image is bootfs. This layer is the same as our typical Linux/Uni system, including the boot loader and the kernel. When the boot load is complete, the entire kernel is in the memory. At this time, the right to use the memory has been transferred from the bootfs to the kernel, and the system will also unload the bootfs at this time.

rootfs (root file system), on top of bootfs. Included are standard directories and files such as /dev, /proc, /bin, /etc in a typical Linux system. Rootfs is a variety of different operating system distributions, such as Ubuntu, Centos and so on.

Common commands for mirroring

Enter the docker command directly to view all the command options of the Docker client.
Use docker command --help to learn more about the usage of the specified Docker command.
Commonly used:

docker pull ubuntu //Pull the image
docker image //View the local image
docker rmi -f image id //Delete the image
docker rmi -f $(docker images -aq) //Delete all the images

Common commands for containers

Run the container

docker run [optional parameter] image id //start with a new image container

Optional parameter description:

  • --Name specifies the name of the container
  • -d run in background
  • -it run in interactive mode, enter the container to view
  • -p specifies the port of the container -p 8080:8080
    -p ip: host port: container port
    -p host port: container port (commonly used)
    -p container port (there is no open port)
    port
  • -P random designated port

docker run -it ubuntu /bin/bash //Start the container example
// -i means interactive operation, -t means terminal, after mirroring ubuntu is a command, interactive shell

View container

docker ps [optional parameter]

Optional parameter description:

  • -a: on behalf of viewing all containers, including not running
  • -q: Only view the identity of the container
  • -f: Filter the displayed content according to conditions
  • --Format: Specify the template file of the return value
  • -l: Display recently created containers
  • -n: List recently created n containers
  • --No-trunc: do not truncate the output
  • -s: Display the total file size

Start and stop the container

docker start container id //start the container
docker restart container id // restart the container
docker stop container id // stop the running container
docker kill container id // force stop the container

Delete and exit the container

docker rm container id //Delete the container (you need to stop the container before deleting, unless it is forced to delete)
docker rm -f $(docker ps -aq) //Delete all containers
docker ps -a -q | xargs docker rm //Delete all Container
exit //Exit directly
Ctrl + P + Q //The container does not stop and exit

Other container commands

View log

docker logs [optional parameter] container id

Optional parameter description:

  • -t show log
  • -f scroll to view
  • --Tail number The number of logs displayed

View process information

docker top container id

Guess you like

Origin blog.csdn.net/MinutkiBegut/article/details/115291592