Docker common commands collate of utilities
- 2020-06-07 05:35:42
- OfStack
1. View docker information (version, info)
# To view docker version
docker version
# According to docker System information
docker info
2. 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 his
3. Start the container (run)
The docker container can be understood as a process running in a sandbox. This 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
# in 1 Second step into the container that you just entered
docker exec -i -t [ The container ID]
Note: When executing the apt-ES26en command, take the -ES27en argument with you. If the -ES28en parameter is not specified, the ES29en-ES30en command enters interactive mode, requiring user input for confirmation, but this interaction is not possible in the docker environment. After the apt-ES33en command completes, the container stops, but changes to the container are not lost.
Step 4 View the 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
5. 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
6. Operation of containers (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 in the same container at the same time. You can also detach from one container, CTRL-ES63en.
7. 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 And then :
docker load < /home/save.tar
8. Login to registry server (login)
# landing registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Usernamedocker login
9. Release of image (push)
# release docker The mirror
docker push new_image_name
10. Build a container according to 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
Other references:
http://blog.csdn.net/wsscy2004/article/details/25878363
http://blog.csdn.net/iloveyin/article/details/40542431