[docker] Some common commands of docker ------- Day 92 of learning operation and maintenance from novice to master

Table of contents

1. Install docker-ce

1. Download the docker-cer.epo source from Alibaba Cloud

2. Download some dependencies

3. Install docker

2. Enable docker

1. Start docker or check docker version without starting it.

2. What is the difference between starting the service and checking the docker version? see it?

3. Check what is in the image warehouse after docker is started. There is nothing.

4. There is no mirror, right? So let’s download the mirror and see how to download it?

5. Now I have the image of nginx, but what if I have it locally?

6. Then the problem comes again. What should I do if I download an image package that is not a tar package? Downloaded a gz compressed package?

7. I now have three images. I don’t want some of them now, but I can’t guarantee that I won’t use them in the future. I don’t want to download them again. What should I do?

8. Hey, I have a brain twitch and I want it again. What should I do?

3. Running containers in docker

1. Run nginx

The first method: create and start work together

The second method: run with one click

 2. I no longer run it. I want to delete it. How can I delete it?

The first method: stop and then delete

The second method: direct deletion, forced deletion

3. The running image is called a container, so it is called a container. Can I go in and see it?

The first entry method: exec

First exit method:

Second exit method:

The second entry method: attach

First exit method:

Second exit method:


The basic environment needs to be set up. First, make sure you can connect to the Internet. Secondly, the yum warehouse is also set up. It is best to rebuild the cache.

1. Install docker-ce

1. Download the docker-cer.epo source from Alibaba Cloud

[root@huyang1 yum.repos.d]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2. Download some dependencies

[root@docker ~]# yum -y install yum-utils device-mapper-persistent-data lvm2

3. Install docker

[root@huyang1 yum.repos.d]# yum - ysintall docker-ce

2. Enable docker

1. Start docker or check docker version without starting it.

[root@docker ~]# systemctl start docker
[root@docker ~]# vim /etc/docker/daemon.json


[root@docker ~]# systemctl daemon-reload
[root@docker ~]# systemctl restart docker

2. What is the difference between starting the service and checking the docker version? see it?

[root@docker ~]# docker version

3. Check what is in the image warehouse after docker is started. There is nothing.

[root@docker ~]# docker images
[root@docker ~]# docker ps -l
[root@docker ~]# netstat -antpl|grep docker

4. There is no mirror, right? So let’s download the mirror and see how to download it?

If there is a compressed image package, we can import it. How to import it? No, how to download it?

Take nginx as an example

[root@docker ~]# docker pull nginx  

5. Now I have the image of nginx, but what if I have it locally?

[root@docker ~]# docker load < nginx-1.14.tar

6. Then the problem comes again. What should I do if I download an image package that is not a tar package? Downloaded a gz compressed package?

[root@docker ~]# cat centos-7-x86_64.tar.gz |docker import - centos:7

7. I now have three images. I don’t want some of them now, but I can’t guarantee that I won’t use them in the future. I don’t want to download them again. What should I do?

I'll make a backup first and then delete this image.

[root@docker ~]# docker save -o nginx-latest-images nginx:latest backup this image

[root@docker ~]# docker rmi nginx:latest Delete this image

8. Hey, I have a brain twitch and I want it again. What should I do?

[root@docker ~]# docker load < nginx-latest-images

3. Running containers in docker

1. Run nginx

The first method: create and start work together

[root@docker ~]# docker create -it nginx:latest /bin/bash is built but not completely built.

[root@docker ~]# docker start f9 I have to start it myself. Is this troublesome?

The second method: run with one click

[root@docker ~]# docker run -itd nginx:latest /bin/bash

 2. I no longer run it. I want to delete it. How can I delete it?

The first method: stop and then delete

[root@docker ~]# docker stop 0c

[root@docker ~]# docker rm 0c

The second way to stop

[root@docker ~]# docker kill d5

The second method: direct deletion, forced deletion

[root@docker ~]# docker rm -f d5

Now comes the key point of this section, so pay attention! ! !

3. The running image is called a container, so it is called a container. Can I go in and see it?

The first entry method: exec

[root@docker ~]# docker exec -it 5b /bin/bash

 So how to exit?

First exit method:

exit

Second exit method:

ctrl +p ctrl +q Commonly used

The second entry method: attach

[root@docker ~]# docker attach 5b0

First exit method:

exit

Second exit method:

ctrl +p ctrl +q Commonly used

    Did you see it? Did you see it? Did you see it?

Two entry methods, two exit methods, different results! ! ! see it?

Therefore, in our future work, we often use the exec method to enter and exit using ctrl +p ctrl +q to ensure the normal operation of the container. Of course, if you always remember this principle, you can use it casually.

So, due to time constraints, today’s sharing ends here! ! !

If you are interested in children's shoes, you can click and follow, there will be more follow-up! ! !

Guess you like

Origin blog.csdn.net/2302_77582029/article/details/132604415