CentOS install docker

Time:2020-8-14

1. Install docker

  • Root permission is required
sudo su root
  • Install docker
yum install docker
  • Enter y to confirm installation

2. Start docker

  • start-up
systemctl start docker
  • View version number
docker -v

CentOS install docker

3. Set docker to start automatically

systemctl enable docker

CentOS install docker

4. Stop docker

systemctl stop docker

5. Common operations

-Image search
-Pull image
-Start container based on image
1. Mirror operation
  • Retrieve image
docker search xxx

CentOS install docker
Index: index
Name: image name
Description: Introduction
Stars: number of followers (k)
Officail: is it official
Automated: whether it will be configured automatically

  • Pull image
docker pull xxx:tag 

Most of the images are specified by tag
The image searched by the command line does not have a tags tag. At this time, we need to retrieve the docker hub to find the tags
CentOS install docker

  • View local image list
docker images

CentOS install docker

  • Delete the specified local image
docker rmi image-id
2. Container operation
  • function
docker run --name container-name -d image-name
eg:docker run --name custommysql -d mysql
Container name: Custom container name
-D represents background operation
Image name: image name, need to be labeled, the default is latest
  • list
View running containers
docker ps
View all containers
docker ps -a
  • Stop the currently running container
docker stop container-id/container-name
  • Start container
docker start container-name/container-id
  • Delete specified container
The container must be stopped
docker rm container-id
  • Port mapping
Set port mapping when docker runs
-P host port: container port
  • Container log
docker logs container-id/container-name

6. Solution to slow download of docker image (alicloud)

  • Registered account number
  • Search container mirroring service
  • Create image warehouse
  • Find the mirror accelerator
  • Find how to configure the image accelerator
  • Select your own operating system, copy and paste

7. Problems encountered

  • Docker run error

CentOS install docker
When docker runs again, it will prompt that the container name already exists, but docker PS cannot find it
Solution: This is because of the compatibility between Linux and docker versions. The download version of Yum install docker is too high. Just update Linux

yum update
  • After tomacat container configuration mapping (404)

There are three possibilities:

1. Turn off the firewall of the host
    Shut down firewall command: systemctl stop firewalld.service
    Opening firewall: systemctl start firewalld.service
    System CTL disable firewalld.service
    Start: systemctl enable firewalld.service
2. If you use cloud server, you need to set the security group zuxinxin
    The lightweight application server of alicloud is selected here. It is good to set the firewall release port
3. There are two webapps directories in the Tomcat image downloaded by default
    -Webapps: this folder is empty. There is nothing in it
    - webapps.dist There are complete Tomcat folders and files.
Solution: delete the empty folder and rename it webapps.dist For webapps
    docker exec -it container-id /bin/bash
    rmdir webapps
    mv webapps.dist webapps