In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. Concept
The container is similar to a linux environment, which is started by image creation, which can be understood as creating a read-write layer on the top layer of the image. The image itself is read-only, and the read and write of the container will not change the image.
2. Container Management 2.1 creation of containers
# docker run-itd-- name nginx1 nginx:latest
The basic creation can be done with the three parameters i t d, which can be expressed as follows
-I: runs the container in interactive mode, usually in conjunction with-t
-d: runs the container in the background and returns the container ID
-t: reassign a pseudo-input terminal to the container, usually used in conjunction with-I
Nginx1 and nginx:latest represent the name of the created container and the image used, respectively. After the creation is completed, you can use the docker ps command to see the newly created and running container.
# docker run-itd-- name nginx2-p 8080 nginx:latest
Specify the mapping port and map port 80 in the container to port 8080 of the host, so that the container can be accessed by accessing port 8080 of the host.
# docker run-itd-- name nginx3-- cpus 1 nginx:latest
Limit the maximum number of available cores in cpu
# docker run-itd-- name nginx5-- cpu-shares 512 nginx:latest
Set the weight of cpu, the default value is 1024; do not set it or set it to 0, all use the default value; if all five containers are default value 1024, it is evenly distributed
# docker run-itd-- name nginx4-m 100m nginx:latest
Limit the maximum available memory
# docker run-itd-- name nginx6-m 100m-- oom-kill-disable nginx:latest
By default, when an out-of-memory (OOM) error occurs, the system kills the processes in the container to get more memory space; oom-kill can be disabled after using-m to limit the container memory
2.2 query for containers
# docker ps
Query the currently running container
# docker ps-a
Here we first use docker stop nginx1 to close the nginx1 container, and then use-a to see all the container information
# docker ps-aq
Query the id numbers of all containers
# docker log nginx2
View the log information of the container
# docker inspect nginx2
Used to query the details of the container, including cpu, content, port, directory, etc.
# docker top nginx2
Query the process information of the container
# docker port nginx2
View the port mapping of the container
# docker stats nginx2
View the resource utilization of the container in real time
2.3 manipulating the container
# docker exec-it nginx2 bash
Enter the container, and the container is still running after exit
# docker cp / tmp/test.txt nginx2:/tmp
Copy files to the / tmp directory of the nginx2 container; copy the files in the container to the host
# docker start | stop | restart nginx2
That is, start, stop, and restart the container
# docker rm nginx2
Delete and restart. Make sure the container is stopped before execution, otherwise rm fails.
# docker commit nginx2 nginx:v2
Submit the container as an image, and the changes to the current container will be persisted into the nginx:v2 image.
3. Data management 3.1 volumes mode
# docker volume create nginx-vol
Create a volume with the specified name nginx-vol
# docker volume ls
Query the volume that has been created
# docker volume inspect nginx-vol
If you view the details of volume, you can see the mount path for
# docker run-itd-- name nginxvol-test-name nginxvol-test 8081-- mount src=nginx-vol,dst=/usr/share/nginx/html nginx:latest
Use volume to create a container and specify the container mount directory as / usr/share/nginx/html
At this point, if you check nginx-vol, you will find that the html files in the directory are mounted in the container, and the new files under volume will also be synchronized to the container.
The Docker inepct command can see the volume information of the container
# docker volume rm nginx-vol
Delete operation can only be performed when nginx-vol is not in use
3.2 bind mode
# docker run-itd-- name nginxBind-test-name nginxBind-test 8082-- mount type=bind,src=/root/www/,dst=/usr/share/nginx/html nginx:latest
Create the container with type=bind and specify the src and dst directories
The docker insepct command can see the bind information of the container
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.