Docker Study Notes (2) -- Common docker commands

Source: Internet
Author: User
Tags docker ps docker cp docker run
1. View docker information (version, Info)
# View docker version $ docker version # display docker System Information $ docker info


2. Image operations (search, pull, images, RMI, and history)
# Search image $ docker search image_name # download image $ docker pull image_name # list images;-A, -- all = false show all images; -- no-trunc = false don't truncate output;-Q, -- Quiet = false only show numeric IDs $ docker images # delete one or more images;-F, -- force = false force; -- no-prune = false do not delete untagged parents $ docker RMI image_name # displays the history of an image. -- no-trunc = false don't truncate output; -Q, -- Quiet = false only show numeric IDs $ docker history image_name


3. Start the container (run)

A docker container can be understood as a process running in a sandbox. This sandbox contains the resources required for running the process, including the file system, system library, and shell environment. However, this sandbox does not run any program by default. You need to run a process in the sandbox to start a container. This process is the only process of the container. When the process ends, the container stops completely.

# Run the "Echo" command in the container, output "Hello word" $ docker run image_name echo "Hello word" # interactively enter the container $ docker run-I-t image_name/bin/bash # install a new program in the container $ docker run image_name apt-Get install-y app_name

Note: The-y parameter must be included when executing the apt-GET command. If the-y parameter is not specified, the apt-GET command enters the interaction mode. You need to enter a command to confirm it. However, in the docker environment, this interaction cannot be responded. After the apt-GET command is executed, the container will stop, but the changes to the container will not be lost.

4. View containers (PS)

# List all currently running container $ docker PS # list all container $ docker PS-A # list the last started container $ docker PS-l


5. save the changes to the container. When you modify a container (by running a command in the container), you can save the changes to the container, in this way, you can run the container from the latest status after saving.

# 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. However, you can dynamically install new software for the instance, and then use the commit command to solidify the container into an image.


6. Operations on 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, and kill a container $ docker stop name/Id $ docker start name/Id $ docker kill name/ID # retrieve logs from a container; -F, -- follow = false follow log output;-T, -- timestamps = false show timestamps $ docker logs name/ID # list the files or directories changed in a container, three events are displayed in the list, which are added by a and deleted by D, c changed $ docker diff name/ID # display the process information in a running container $ docker top name/ID # copy the file/directory from the container to a local path $ docker CP Name: /container_path to_path $ docker cp id:/container_path to_path # restart a running container;-T, -- time = 10 number of seconds to try to stop for before killing the container, default = 10 $ docker restart name/ID # attach to a running container; -- no-stdin = false do not attach stdin; -- sig-proxy = true proxify all attached ed signal to the process $ docker attach ID

Note: The attach command allows you to view or affect a running container. You can attach the same container at the same time. You can also detach a container from Ctrl-C.


7. Save and load images)

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

# Save the image to a tar package;-o, -- output = "" write to an file $ docker save image_name-O file_path # load an image in the TAR package format;-I, -- input = "" read from a tar archive file $ docker load-I file_path # machine a $ docker save image_name>/home/save.tar # Use scpto copy save.tar to machine B, and then: $ docker load 


8. log on to the Registry server (LOGIN)
# Log on to the Registry server;-E, -- email = "" email;-P, -- Password = "" password;-u, -- username = "" username $ docker Login


9. Publish image (push)
# Publish a docker image $ docker push new_image_name

10. Build a 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






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.