Docker common commands are detailed

  • 2020-06-15 10:32:51
  • OfStack

Docker common commands are detailed

View Docker information (version, info)


#  To view docker version 
$docker version

#  According to docker System information 
$docker info

Operation on image (search, pull, images, rmi, history)


#  retrieve image
$docker search image_name

#  download image
$docker pull image_name

#  Make a list of images ; -a, --all=false Show all images; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs
$docker images

#  delete 1 One or more mirrors ; -f, --force=false Force; --no-prune=false Do not delete untagged parents
$docker rmi image_name

#  According to 1 The history of the mirror ; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs
$docker history image_name

Start the container (run)

The docker container can be understood as a process running in a sandbox. The sandbox contains the resources necessary for the process to run, including the file system, the system class library, the shell environment, and so on. But the sandbox doesn't run anything by default. You need to run a process in the sandbox to start a container. This process is the only one in the container, so when the process ends, the container stops completely.


#  Run in the container "echo" Command, output "hello word"
$docker run image_name echo "hello word"

#  Enter the container interactively 
$docker run -i -t image_name /bin/bash


#  Install the new program in the container 
$docker run image_name apt-get install -y app_name

Note: When executing the ES29en-ES30en command, take the -ES31en parameter. If the -ES32en parameter is not specified, the ES33en-ES34en command goes into interaction mode, requiring user input for confirmation, but this interaction cannot be responded to in the docker environment. After the apt-ES37en command completes, the container stops, but changes to the container are not lost.

View container (ps)


#  Lists all currently running container
$docker ps
#  List all container
$docker ps -a
#  Recently listed 1 Time to start container
$docker ps -l

Save the changes to the container (commit)

When you make a change to a container (by running a command in the container), you can save the changes to the container so that the next time you run the container from its latest state.


#  Save the changes to the container ; -a, --author="" Author; -m, --message="" Commit message
$docker commit ID new_image_name

Note: image is equivalent to a class and Container is equivalent to an instance, but you can dynamically install new software on the instance and then solidify the container into a single image using the commit command.

Operation of the container (rm, stop, start, kill, logs, diff, top, cp, restart, attach)


#  Delete all containers 
$docker rm `docker ps -a -q`

#  Delete a single container ; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container
$docker rm Name/ID

#  Stop, start, kill 1 A container 
$docker stop Name/ID
$docker start Name/ID
$docker kill Name/ID

#  from 1 Take logs from a container ; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps
$docker logs Name/ID

#  list 1 A container of files or directories that have been changed, list The list will display 3 Kind of event, A  The increase, D  Delete, C  Be changed 
$docker diff Name/ID

#  According to 1 Process information in a running container 
$docker top Name/ID

#  Copy the file from the container / Directory to local 1 A path 
$docker cp Name:/container_path to_path
$docker cp ID:/container_path to_path

#  restart 1 Three running containers ; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10
$docker restart Name/ID

#  Attached to the 1 On top of a running container ; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process
$docker attach ID

Note: The attach command allows you to view or affect 1 running container. You can have attach with 1 container at the same time. You can also detach from one container, CTRL-ES77en.

Save and load images (save, load)

When you need to migrate an image from one machine to another, you need to save the image and load the image.


#  Save the image to 1 a tar package ; -o, --output="" Write to an file
$docker save image_name -o file_path
#  loading 1 a tar A mirror image of the package format ; -i, --input="" Read from a tar archive file
$docker load -i file_path

#  The machine a
$docker save image_name > /home/save.tar
#  use scp will save.tar Kao to the machine b Go, then: 
$docker load < /home/save.tar

Login to registry server (login)


#  landing registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Username
$docker login

Release image (push)


#  release docker The mirror 
$docker push new_image_name

Build 1 container based on Dockerfile


#build
   --no-cache=false Do not use cache when building the image
   -q, --quiet=false Suppress the verbose output generated by the containers
   --rm=true Remove intermediate containers after a successful build
   -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success
$docker build -t image_name Dockerfile_path

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: