catalogue
1, Docker introduction
Docker is a new virtualization tool in recent years. It can isolate resources and system environment like virtual machine.
The difference between docker and virtual machine:
The difference between virtual machine and container
1. Docker has three elements: image, warehouse and container
Image: like the image in the virtual machine, it is a read-only working environment for the container. When we use it, we can define different images to adapt to different working environments
Warehouse: the place where images are stored. Similar to git and maven warehouses, there are local warehouses, private warehouses and official warehouses
Container: it is a virtual machine like working environment developed by Docker. You can build an environment in the container and publish projects
2, Installation
1. Uninstall old version
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
2. Install system tools
yum install -y yum-utils device-mapper-persistent-data lvm2
3. Add Docker yum
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Ali source
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4. Update source cache
yum makecache fast
There may be problems here. If there are problems, turn off the original process first
-- rm -f /var/run/yum.pid
5. Install Docker
yum -y install docker-ce
1) The latest stable version is installed by default
2) To view the version list, use the following command:
yum list docker-ce --showduplicates | sort -r
3) If you want to install a specific version of docker CE, use the following command format:
yum install docker-ce
3, Basic use
Because it was downloaded from yum, you can directly operate with systemctl
1. Preparatory work
Configure Alibaba cloud exclusive image acceleration address
vi /etc/docker/daemon.json
Document content:
{ "registry-mirrors":["Your Alibaba cloud exclusive accelerator address"] }
Reload the daemon
systemctl daemon-reload
Restart docker
systemctl restart docker
2. Image download
Search image
docker search Image name
Download Image
docker pull Image name
To obtain the basic image of a centos system, you can use the following command:
docker pull centos (if no version is specified, the latest version will generally be used)
docker pull centos: version number (or specify the version directly)
View the mirror on the host
docker images
View image location (image: mirror)
cd /var/lib/docker/containers && ll
/var/lib/docker is the default installation directory of docker
Remove mirror
docker rmi Image name
Force removal
docker rmi -f Image name:edition
Docker commands start with docker
If you are prompted that the image is used and you need to stop the container with a certain ID, delete the container first and then delete the image. Or forcibly delete the image. Correct approach: delete all containers that depend on the image first, and then delete the image
4, Container
Container is another core concept of Docker. Simply put, a container is a running instance of an image. The image is a static read-only file, and the container has a writable file layer required by the runtime. At the same time, the application process in the container is running
1. Create container
docker create -it centos:latest
Specify name:
docker create -it --name centos01 centos:latest
Docker will check whether the specified image exists locally. If it does not exist, it will be downloaded from the public warehouse
start-up
docker start container ID|name|name:tag
stop it
docker stop container ID|name|name:tag
restart
docker restart container ID|name|name:tag
2. View current container
View currently running containers
docker ps
View all
docker ps -a
3. Delete container
docker rm container ID
Force deletion
docker rm -f container ID
4. Entry and exit
get into
docker exec -it container ID/container NAME /bin/bash docker exec -it container ID/container NAME bash (Abbreviation)
sign out
If you want to continue running the container when exiting: press [ctrl+p] and [ctrl+q] in sequence
If you do not want to continue running: press [ctrl+d] or enter exit