[Docker operation and maintenance] Docker basic quick start tutorial

The basic docker operation part includes docker installation, docker startup, docker operation, docker shutdown, and docker deletion. It is mainly aimed at ordinary users and recommends systematic learning for those who need in-depth understanding.

docker basics

From the rookie tutorial [https://www.runoob.com/docker/docker-tutorial.html]

Docker is an open source application container engine, based on the Go language and open source following the Apache 2.0 protocol.

Docker allows developers to package their applications and dependent packages into a lightweight, portable container, and then publish to any popular Linux machine, it can also be virtualized.

Containers use the sandbox mechanism completely, and there will be no interfaces between them (apps similar to iPhone), and more importantly, the container performance overhead is extremely low.

Docker has been divided into CE (Community Edition: Community Edition) and EE (Enterprise Edition: Enterprise Edition) since version 17.03, we can use the Community Edition.

docker installation

Under the centos system, docker only supports version 7 and above. This article takes centos8 as an example.

Add a docker-ce repo source, and then install the dependencies, it may be prompted to add some command parameters to install the dependencies, just follow the prompts.

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

Then install docker

   yum install -y  https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.13-3.2.fc30.x86_64.rpm
   yum install docker-ce docker-ce-cli

If no error is reported, the installation is completed!

docker start

systemctl start docker

In this way, the docker service is started and you can start using the docker command

docker operation

There are many docker operations, and the more commonly used ones are downloading mirrors, loading mirrors, entering mirrors as administrators, copying from mirrors, copying into mirrors, mirroring internal updates, etc.

Docker download and install the image

In the winter of installing docker, I just simply wanted to download a deployed collaboration online service from the Internet for the online office browsing of nextcloud. Here is an example.

docker pull collabora/code

Through the above command, the image is downloaded to the local.

Run/start the image and generate a container

docker run -t -d -p 0.0.0.0:9980:9980 -e 'domain=192\\.168\\.1\\.110|192\\.168\\.33\\.145' -e "username=admin" -e "password=123456" --restart always --cap-add MKNOD collabora/code

The above code comes from the short book: https://www.jianshu.com/p/4082f998a05b

To run the image, mainly use docker run. Refer to the tutorial for specific usage: https://www.runoob.com/docker/docker-run-command.html

In addition, docker stop/stats/ps/restart… and so on are commonly used, not to explain them one by one.

Enter the container

When we run a container, we need to obtain the container ID (container ID) in order to operate on the specific container

docker ps -a

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-YCUKOMJ7-1607782879159)(https://i.loli.net/2020/12/12/DRaxkCwoQh3iEFH.png )]

As shown in the last line of the above figure, you can see the container ID, and then we enter this container

docker exec -it 1e560fca3906 /bin/bash

Or enter the container as an administrator, so that you can modify the content in the container

docker exec -it --user root 1e560fca3906 /bin/bash

But for my container, the vim command is deleted, and I can't do anything, so the administrator needs to install commands on the container after logging in. To update, you first need to know the docker system type, the operation here is the operation of linux.

cat /etc/issue

Then I found that this docker is Ubuntu, and we also need to start from adding the source. Since vim cannot be used, we can do the following and add the source directly.

echo deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse >> /etc/apt/sources.list

Update the management toolkit and install vim

apt-get update
apt-get install vim

In this way, you will find that the container is actually another linux world, just a doll.

docker copy

Initially, I used this command because there was no vim command. I wanted to copy it out and put it back in. It turned out that even the user was not the same for this operation, which finally caused insufficient permissions. It is not recommended, but it may be useful, so let’s briefly talk about it for record.

Native-"docker

docker cp copy.txt 1e560fca3906:/usr/local/

docker-》local

docker cp 1e560fca3906:/usr/local/copy.txt /home/

Close the container, delete the container

docker stop 1e560fca3906
docker rm 1e560fca3906

There can also be batch methods to stop and delete all containers

docker stop $(docker ps -a -q) //  stop停止所有容器 
docker rm $(docker ps -a -q) //   remove删除所有容器

Guess you like

Origin blog.csdn.net/u010472858/article/details/111086163