In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Today is the final chapter of the Docker discussion series. Let's start with the docker command and then explain the key parameters of the Docker run command.
If you haven't seen the previous content:
The first article "what is the nature of containers?" Where does the container come from? "
The second article, "introduction to the installation and Architecture of Docker"
A picture to understand the docker command
The above image is excerpted from http://bingohuang.com/simplify-docker-image-2/
1. Concept introduction:
Images:docker image. Containers can be converted into images, and container instances can also be run from the images. Similar to the concept of a virtual machine template.
Container: container.
There are three states of running\ stopped\ pause, similar to the concept of a virtual machine.
Tar files: you can package the image as a tar file, or you can re-load the packaged tar file as an image
Dockerfile: build a declarative configuration file for the image. One of the core highlights of Docker technology. When we build another basic image (such as java image) from one basic image (centos image), we generally do not use the method of installing java directly in the centos image. Instead, we put the java software together with the centos image, and write dockerfile,dockerfile in the same directory to define installation information such as java image installation commands and environment configuration parameters. The software and configuration files can then be packaged into a java image using the docker build command. The advantage of this is that a pure image file is finally built through this declarative build.
Registry: image repository. Used to store image files.
Engine:docker engine
two。 Commands related to Engine
Docker version View docker version
Docker info displays Docker system information, including images and number of containers.
Docker events gets real-time events from the server
3. Container-related commands
Status operation command:
Docker start from stop to running
Docker kill from running to stop, direct kill container process
Docker stop from running to stop, the container completes some protective actions before stopping and then stops the container.
Docker pause pauses all processes in the container
Docker unpause restores all processes in the container
Container operation commands related to image:
Docker commit saves the container as a new image
Docker create creates a container from the image with a state of stop
Docker run creates a container from the image and starts the container
Docker diff checks the changes in the file structure in the container since the image is run.
Container operation commands related to tar files:
Docker export exports the container as a tar file
Other operation commands of the container itself:
Docker inspect acquires container / mirror metadata
Docker attach connects to a running container
Docker port lists the port mappings for the specified container
Docker ps views containers in the system
Docker top views the process information running in the container
Docker rm delete container
Docker logs gets the container log
Docker wait blocks running until the container stops, and then prints out its exit code
Docker exec executes commands in the running container
Docker network operates the container network
4. Mirror-related commands
Container operation commands related to image:
Docker commit saves the container as a new image
Docker create creates a container from the image with a state of stop
Docker run creates a container from the image and starts the container
Docker diff checks the changes in the file structure in the container since the image is run.
Mirror tar files-related commands:
Docker import mirrors the tar file load, resulting in the loss of related metadata and history
Docker load load the tar file as a mirror
Docker save saves the image as a tar file
Mirror dockerfile-related commands:
Docker build builds images based on dockerfile
Mirror warehouse-related commands:
Docker pull downloads images from the repository
Docker push uploads the image to the repository
Command to mirror itself:
Docker images enumerated image
Docker rmi Delete Mirror
Docker tag tags the image
Docker inspect lists the details of the image
Docker history lists the construction history of the image
5. Commands related to tar files
Docker export exports containers to tar files
Docker import mirrors the tar file load, resulting in the loss of related metadata and history
Docker load load the tar file as a mirror
Docker save saves the image as a tar file
6. Dockerfile-related commands:
Docker build builds images based on dockerfile
7. Registry-related commands:
Mirror warehouse-related commands:
Docker pull downloads images from the repository
Docker push uploads the image to the repository
The command of the warehouse itself:
Docker search looks for an image in the repository
Docker login logs in to the warehouse
Docker logout logs out of the warehouse
Learn schematic diagram of other docker commands
The Docker command learning diagram:
Photo Source: https://blog.csdn.net/yuanfenger/article/details/73316481
The Docker command learning diagram:
Photo Source: https://www.twblogs.net/a/5c290471bd9eee01606d2e41
Introduction to Docker run command
The purpose of the Docker run command is to generate a container instance from a container image and start it.
The main command parameters for Docker run are as follows:
Description of key parameters of Docker run command
1.-I-t-d
Use docker run-it [IMAGE_NAME] to launch a container and enter the command line interface:
Use exit to exit this container
Use-d to make the container run in the background:
2.-- ip
-- ip can specify the ip address for the container. First, use docker network ls to view the docker network on the host:
Start the container with the-- ip parameter:
An error is reported at this time. If you want to use a custom ip, you can only use a custom container network. First create a custom container network:
You can also manually specify the subnet of the container at creation time:
Rerun the command for the specified container ip:
If the execution is successful, check the container ip address:
3.-h-name
-h specifies the hostname in the container, and-- name specifies the name of the container
4.-p
-p can map the port on the host to the container. -p 8088Suzhou 80 means that port 8088 of the host is mapped to port 80 of the container:
5.-v
-- privileged means to give this container permission to change files on the host, and-v means to map the / host/v1 directory of the host to the / con/logs directory on the container, which will be created automatically if it does not exist in the container. Execute a command
Docker run-it-- privileged-v / host/v1:/con/logs centos
The contents written to that directory in the container can be seen in the appropriate directory on the host.
Mount the volume on the host for the container and set the container to have read-only access to this volume:
Docker run-it-privileged-v / host/v1:/con/logs:ro centos
6.-m-c
-m is used to specify container memory, and-c can be used to specify the cpu quota of the container
We can download the progrium/stress container to test the quota assignment of the container. Use the following command to see what testing functions the container has:
Using docker run-m 2000m, you can start a memory-consuming 2000MB container, but when there are no processes in the container, the container does not directly occupy the memory of the host 2000MB. At this point, we can start the stress container and use-- vm 1 and-vm-bytes 2000m to indicate that when we start the stress container, start a process that takes up 2000m of memory:
If we start three 500MB-consuming processes in a stress container with a total limit of 2000MB, with a total of 1500MB, the situation is as follows:
Processes that exceed the container memory limit are run in the container:
With regard to cpu restrictions,-- cpu-share represents the definition of the cpu usage weight of the container running on the host. Since there are four cpu cores on the host, the-- cpu 4 parameter is required to start four processes in the container to fill all the cpu of the host.
With regard to the-- cpus parameter in docker run, specify the number of cpu. When there are four cpu on the host, the container will only use a total of 1 cpu, that is, 1 / 4.
This value can also be a decimal, such as 0.5, then the container will only use 1 / 8 of the host's cpu.
When the value is the same as the host's cpu core, all cpu quotas for this host will be available, and you can see that 4 cpu are full.
We can start five processes full of cpu instead of four, as follows:
Author: Shen Xiaolong
Good article recommendation
Docker Operation practice (2): introduction to the installation and Architecture of Docker
Docker Operation practice (1): what is the nature of a container? Where does the container come from?
Batch automatic Publishing of Oracle Database using sqlplus
What if the business is complex, the data is huge and the application is wide? Understand the solution to distributed transactions!
Ganzhou Bank strengthens scientific and technological innovation and realizes one-click disaster preparedness switch.
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.