View
Docker PS
There are some main parameters to say
1. Without parameters, to view the currently running container
2. A, view all containers including the stop state of the container
3-L to view the newly created container
4.-n=x, view the last created X container
Make a list of the results of Docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
What do these separate represent?
CONTAINER ID: Container ID, unique identity container
Image: Mirror used when creating a container
Command: Commands that run at the end of the container
CREATED: Time the container was created
Status: The state of the container (you will see the upxxx, indicating the running state)
PORTS: The port slogan of opening to the outside
NAMES: Container name (also unique, Docker is not allowed to create containers with the same container name)
Start
When we use Docker ps-a we see that some of the container states are created, and here we need to start the container with the Docker start container name or the container ID. However, it should be noted that, with this command, the container enters the running state, and when the container completes its task, it exits itself and enters the stop state. If you need to start the start command again
Here is a parameter that allows the container to automatically restart after exiting
--restart This parameter checks the exit code of the container and accordingly determines whether the container should be restarted.
This example should not be easy to try, this will keep the output of Hello World, with CTRL + C did not stop this (after here to think about why did not stop ...) )
Finally, I opened another terminal and typed it in.
Docker stop Docker_restart terminated the container
Also said in the above command is
Docker stop container name or container ID
And this docker Stop command sends a sigterm signal (can be captured) to the container process, and the default behavior is that the container exits.
If you want to force a container to stop, it's best to use the Docker kill command
It is to send a sigkill signal (not to be captured) to delete
We can not delete a running container, we must first Docker stop or Docker kill before we can remove
Command: Docker RM container Name
of course, if we add the-f parameter We can also delete a running container
How to delete all containers at once Docker did not give the relevant command, but we can do so
-Q is a list of container IDs only