Docker use - Containers

View container

Command: docker ps [options]

options are:

-a: View all containers, comprising (a container without running -a parameter is only shown) is not running

-q: Show only the container ID

-s: pay more to show a total file size

-l: display container (docker ps -l) recently created

-n: display n containers recently created (docker ps -n 3, show three containers recently created)

--filter: according to the conditions filter (Not common, a large number of containers not to that extent required filter to find)

 

Start container 

Method 1: Create a container from a mirror and start at the same time

docker run [options] mirror image name or ID [command] [agrs]

Often options:

  -d: Let docker run in the background rather than a direct result of the execution of the command output in the current host machine.

  -t: Let docker assigned a pseudo-terminal (pseudo-tty) and is bound to the standard input of container (with the use -i)

  -i: make a standard container input remains open (use with -t)

   --name: container name

  --restart: whether to follow the host boot (the default is "no", you may have "always")

  --privilleged: whether to allow the vessel to have root privileges (which can be accessed false or true)

  -v: Create a data volume

  -p: Binding port, the local port mapped to a container port, -p local port: container port because the port is listening within the container, the machine does not know, so to access the machine from outside the port access invisible, so do maps

Second way: Start an existing container

Command: docker start container vessel name or ID

 

Stop the container

Command: docker stop [options] name or the container ID of the container

options are:

  -t: container before killing the process, giving the vessel to stop time (default is 10 seconds)

 

Restart container

Command: docker restart [options] name or container ID of the container

options are:

  -t: container before killing the process, giving the vessel to stop time (default is 10 seconds)

Even if the container is turned off, you can restart this point, unlike supervisor, supervisor of the process is off, then you can not restart, can only start

 

Delete container

Command: docker rm [options] name or container ID of the container

options are:

  -f: force the removal of the container (by default, only the state of the container is stopped before they can be deleted, but after take -f, you can delete the vessel in operation directly)

  -l: removing the network link between the container rather than the container itself (do not know, it seems to have used less)

  -v: Delete the volume associated with the container (this can still be there)

 

Batch delete container

Command: docker rm -f $ (docker ps -a -q)
is not new knowledge

 

Container orders executed outside of the container

Command: docker exec [options] container or container name ID [command]

General: docker exec -it container vessel name or ID / bin / bash, for entering the container, whether it can do other operations on the outside, temporarily unknown, I verified: docker exec container name echo "hello world "> test.txt, unsuccessful

 

View container logs

Command: docker logs container vessel name or ID

 

Copy the contents between the host and the container (not recommended, the container only operation, it is best not entered, copy the file, map data volume can be made)

Host copy to the container

Command: docker cp host file container or container ID name: container directory

Somewhat similar to the content between the local and remote server copy: scp native file remote server: Directory

Copy container to the host

Command: docker cp container or container ID name: directory / file local directory

Guess you like

Origin www.cnblogs.com/hf8051/p/11445316.html