Install the official Docker source

sudo yum-config-manager  \
--add-repo  \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code
# yum makecache fastCopy the code

The installation

 yum install docker-ce
Copy the code

Set automatic startup upon startup

 systemctl enable docker
Copy the code

Start Docker and view the version

systemctl start docker
docker version
Copy the code

Docker default image address

https://hub.docker.com/
Copy the code

mirror

  • Download mirror
docker pull name:tag
Copy the code

  • View local downloads
docker images
Copy the code

  • Remove the mirror
docker rmi imageId
Copy the code

Port operations

docker run --name nginx-1 -d -p 8080:80Nginx background startup: -d Port mapping: -p80:80Multi-port mapping: -p80-90:80-90
Copy the code

Mount operation

docker run --name nginx-2 -d -p 8081:80 -v /data:/usr/Share /nginx/ HTML nginx directory mapping -v /data:/usr/share/nginx/html
Copy the code

/data no content, report 403

Vim /data/index.html Enter the content of Hello test

Log operation

Docker logs -f nginx1 Docker logs -f Container IDCopy the code

Container operation

docker exec -it nginx-1Sh # -i Standard input -t terminal # Delete container docker rm -f nginx-1

Copy the code

Network operating

# inspect nginx- docker inspect nginx-2
 
Copy the code

Docker acceleration

  • If the docker image source is aliyun, add parameters to the /etc/docker/daemon.json file and restart the Docker
[root@localhost docker]# vim  daemon.json
[root@localhost docker]# cat daemon.json 
{
"registry-mirrors": ["https://mj9kvemk.mirror.aliyuncs.com"]
}
[root@localhost docker]# pwd
/etc/docker
[root@localhost docker]# systemctl restart docker 

Copy the code