[K8s Study Notes-Introduction to Container Concepts (4)-Reunderstanding Docker Containers]

Use Docker to deploy a web application written in Python

To view the existing directory, first cd develop, which will make changes to develop. Enter develop, create a project mkdir tiger
and then cd tiger to change tiger,
use touch app.py to create the app.py file.
In the same operation, use touch requirements and dockerfile to create these two files.

Insert image description here
As shown above, empty folders have been created separately, and the next step is to fill them with things.
Using the ls command, you can see that there are already three files under tiger.

Use cat app.py to view the content of app.py. You can see that it is blank and we need to fill it in.

Use the vim command to enter the editor, use 'i' to enter the input mode, and then fill in the corresponding codes respectively.
After filling, use: w,:q

Insert image description here
After completing the file filling,
use CMD to start app.py
docker build -t hello word to construct the image.
Insert image description here
After construction, you can query the hello word in the following docker images.
Insert image description here
docker run -p 4000:80 helloworld to run this image.

](https://img-blog.csdnimg.cn/9f7380d9b621411eaa955cf17a988a8d.png)
Then you can see this level locally using
docker ps to check the current program status.
Insert image description here
Insert image description here
Through the following command, you can check that the process number of the container is 2354.
Insert image description here
The principle of docker exec: a process can choose to join a certain process. Namespace, so as to achieve the purpose of "entering" the container where the process is located. This is exactly the implementation principle of docker exec

volume data volume

As I have learned before, container technology uses the rootfs mechanism and Mount Namespace to build a file system environment that is completely isolated from the host.

Consider two questions:

  1. How can the host obtain the files created by the process in the container?
  2. How can the files and directories on the host be accessed by processes in the container?

Volume mechanism:

Allows you to mount the specified directory or file on the host into the container for reading and modification operations. Through the volume mechanism, you can access the host's files in the container, and you can also access the files in the container on the host.

The -v below is to perform the volume operation. You can mount the host directory into the /test directory of the container
$ docker run -v /test …
$ docker run -v /home:/test …

The essence of these two declaration methods is actually the same: they both mount a host directory into the container's /test directory. However, in the first case, since you did not explicitly declare the host directory, Docker will create a temporary directory /var/lib/docker/volumes/[VOLUME_ID]/_data on the host by default, and then put It is mounted on the container's /test directory. In the second case, Docker directly mounts the host's /home directory to the container's /test directory.

Mounting technology

Its main function is to allow you to mount a directory or file, rather than the entire device, to a specified directory. Moreover, any operations you perform on the mount point at this time only occur on the mounted directory or file, and the contents of the original mount point will be hidden and unaffected.

Bind mounting is actually an inode replacement process. In the Linux operating system, inode can be understood as an "object" that stores file content, and dentry, also called a directory entry, is the "pointer" used to access this inode.
Insert image description here

Panorama of docker containers

Insert image description here
Studying on Saturday morning, great

Guess you like

Origin blog.csdn.net/Amelie123/article/details/126315118