This is the 9th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Configuration Docker

  1. Tool Package configuration:yum install -y yum-utils
  2. Configure the domestic download source:yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3. Configure the Docker engine:yum install docker-ce docker-ce-cli containerd.io
  4. View the Docker version number:docker --versionDocker’s latest release is currently 20.10.7
  5. Start the docker:systemctl start docker
  6. Pull to test image, hello Docker:docker run hello-world

So far, the Docker container has been configured. The following are commonly used Docker directives

  • Start the docker:systemctl start docker
  • Stop the docker:systemctl stop docker
  • Restart the docker:systemctl restart docker
  • Automatic startup upon startup:systemctl enable docker
  • Check docker status:systemctl status docker
  • Check docker container status:docker stats
  • View docker information:docker info
  • View the Docker documentation:docker --help

In addition, also need to configure mirror warehouse, there is no existence of Ali

  1. Edit the configuration file vim /etc/docker/daemon.json

  2. Write the configuration information, save the Settings, and exit

    {
        "registry-mirrors" : ["http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn"]
    }
    Copy the code
  3. Reload the configuration and restart the Docker service

    1. systemctl daemon-reload
    2. systemctl restart docker

After configuring the address of the domestic image warehouse, you can quickly download large image files

mirror

  • Pull mirror image:Docker pull < image >
    • You can specify the version of the image. Otherwise, the latest image is pulled by default
    • The downloaded image is stored in the default location/var/lib/dockerThe path
  • Viewing a mirror:docker images
    • REPOSITORY: image name
    • TAG: mirror TAG
    • IMAGE ID: uniquely identifies an IMAGE in the repository
    • CREATED: Indicates the time when the image is pulled and CREATED
    • SIZE: indicates the SIZE of the mirror
  • To delete an image:Docker rmi < image >
    • You can delete the latest mirror by its name and ID. By default, the latest mirror is deleted by its name
  • Search image:Docker search < image >
    • NAME: mirror NAME
    • DESCRIPTION: Mirror DESCRIPTION
    • STARS: Mirror attention
    • OFFICIAL: Indicates whether the image is an OFFICIAL authentication image

The docker container provides a detailed description. You can enter docker search –help to view other commands that can be used when searching for images

Container operation

Starting an image generates a container. The relationship between a class and an instance object in Java. In addition, be familiar with the –help help command, can quickly solve the problem

  • View the container:docker psBy default, view the running containers
    • - a: View all containers, including stopped and running containers
    • - l: Looks at the last running container
  • Run the container:Docker run < image >
    • --name: Specifies the container name
    • -P: Creates port mappings randomly
    • -p xxx:xxx: specifies to establish port mapping. Operating system port: container port
    • -d: Runs the container in the background
  • Start the container:Docker start < container >
  • Stop the container:Docker stop < container >
  • To delete a container:Docker rm < container >
    • The container can be deleted byCONTAINER ID,NAMESUnique identification, rather thanIMAGES
  • Enter the container:Docker exec -it < container > /bin/bash

There are also less commonly used Docker commands, such as copying files

File copy: docker cp < container >:[container path] [host path]

The last

Note: For the introduction of Docker, there is no reference value