Centos7 install docker and docker basic operation

When I used Tencent TSF before, I came into contact with a little bit of docker-related content, but only used a little bit. I didn't understand it for various reasons, but this matter has always been put in my heart, and now I can finally understand it formally.

Centos7 network configuration

According to the instructions of the docker official website installation document, the version required to install the centos system is centos7 or higher. When I learned redis and hadoop before, I used a centos6.5 system saved a long time ago for convenience, so I had to install another centos7 system.
You can choose to upgrade the centos system online. It is said that 6.5 can only be upgraded to 7.2 first, but it should be enough. But out of distrust of the current internet speed, I decided to download the system image and reinstall it, so I directly got the centos7.8 installation package from other colleagues.
The installation process is similar to centos6.5, except that when the network configuration is behind, it is found that the network configuration file is different from the centos, here is a simple record.
In centos6.5, /etc/sysconfig/network-scripts/ifcfg-eth0this file was configured before , and centos7.5 no longer has this file, so I found another similar file for configuration, that is, the /etc/sysconfig/network-scripts/ifcfg-ens33
specific configuration details are basically the same as centos6.5, you can refer to the previous content:
VMware virtual machine Linux system NAT mode network configuration and virtual machine cloning essentials

Yum change source and update

Because it is a brand new virtual machine, again out of distrust of the network, the yum source was changed to Alibaba Cloud for the first time and upgraded. The approximate operation is as follows:

yum install -y wget
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.old
wget http://mirrors.aliyun.com/repo/Centos-7.repo
mv Centos-7.repo CentOS-Base.repo
yum update -y

One thing to add here is that it is said that the yum operation will actually choose the nearest one, so whether there is a difference between replacing the yum source and not replacing it is still to be determined. I have not verified it.
It should be added that some people who are not familiar with linux operation but are accustomed to c/v operation may copy and paste the above lines together. In fact, each line above is a separate operation.

docker installation

The above operations are considered basic environment preparation, but in order to install docker more conveniently, one more preparation is needed, which requires the help of yum-utils:

yum install -y yum-utils

Then, configure the address of the docker software source:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

The url above is the official docker and it points to a foreign address, but I am still very fast in actual operation. If the network is worse, you can choose the following Aliyun:
http://mirrors.aliyun.com/docker-ce /linux/centos/docker-ce.repo

After specifying the installation source, you can use yum to install docker:

yum install docker-ce

Docker basic use

Even if the docker is initially installed, the above operation is very simple. I tried to install it in windows before, but it was not successful. Relatively speaking, the installation of docker in linux is much easier than in windows.

start up

After installation, you can start the docker service for related verification. As a linux service, docker starts up in the same way as other linux services. The following two options are available:

service docker start
systemctl start docker

stop

Similarly, as a linux service, stopping the docker service is also a common operation of linux, you can use the following commands:

service docker stop
systemctl stop docker

Note: Some people may prefer it kill -9, if you just use it yourself, it doesn't matter.

Image and container operations

After the docker service is started, you can use some basic docker commands to use docker, such as image mirror operations:

docker image ls
docker image rm imageName
docker image pull library/hello-world
docker image pull hello-world

The first and second commands above are to list mirrors and delete mirrors respectively, which are almost the same as the operation of the linux file system and the hdfs file system. The second and third are to pull a remote mirror to the local, the effect is the same, the reason there are two, because the default mirror group of docker is library, so it can be omitted, if it is another mirror group, just It must be specified explicitly. However, the image can be automatically captured when running the image, so it is also possible to do without first pulling.

The mirror file is static and cannot provide services. It is similar to the jar or war generated by the system developed by java. Only after running will it provide services or process some logic. To run a mirror, you need to use the following command:

docker container run imageName

The above command specifies that the mirror is started, and a new instance will be run each time. If you just want to start an already running instance, you can use the following command:

docker container start containerId

Correspondingly, if there is a start, there will be a stop. You can use the following two commands:

docker container stop containerId
docker container kill containerId

The difference between the two above is that the former is relatively safe, while the latter will force the container to stop, which is similar kill -9.

The image image is a file, and a file will be generated after the container runs. The viewing operation is similar to the image:

docker container ls
docker container ls --all

The first one above will only display the running container, and the latter one can display all containers. After viewing the specific container information using the above command, if you want to delete the container instance that is no longer in use, you can delete it using the following operations:

docker container rm containerId

In addition to the basic startup, view, and deletion above, for the docker running status, you can also use the command to view the running log:

docker container logs containerId

Docker is a container, which itself is a kind of Linux container after the virtual machine is upgraded, so there are many things in the container, and it also supports the operation of entering the container and entering a running container. The basic commands are as follows:

docker container exec -it containerId

Reference to the above content:
https://www.cnblogs.com/nhdlb/p/11569191.html
http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html
https://docs.docker. com/app/working-with-app/
https://www.cnblogs.com/wang-yaz/p/10429899.html

Guess you like

Origin blog.csdn.net/tuzongxun/article/details/108390634