Docker Learning Notes (2)--docker common commands

Source: Internet
Author: User
Tags commit diff numeric stdin docker ps docker cp docker run
1. View docker information (version, info)
# view Docker version
$docker version

# Displays information about the Docker system
$docker Info


2. Operation on image (search, pull, images, RMI, history)

# Retrieve image
$docker search image_name

# Download image
$docker pull image_name

# List of image lists;-A,--all=false Show all I Mages --no-trunc=false Don ' t truncate output; -Q,--quiet=false only show numeric IDs
$docker Images

# Delete one or more mirrors;-f,--force=false Force;--no-prune=false D o Not delete untagged parents
$docker rmi image_name

# shows the history of an image;--no-trunc=false 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 necessary for the process to run, including the file system, the System class library, the shell environment, and so on. However, this sandbox does not run any programs by default. You need to run a process in the sandbox to start a container. This process is the only process for the container, so when the process is finished, the container will stop completely.

# Run the "echo" command in the container, output "Hello word"
$docker run image_name echo "Hello word"

# Interactive into the container
$docker run-i-T Image_na Me/bin/bash


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

Note: When executing the apt-get command, take the-y parameter. If you do not specify the-y parameter, the apt-get command enters interactive mode and requires the user to enter a command to confirm it, but it is not possible to respond to this interaction in a docker environment. When the Apt-get command finishes executing, the container stops, but changes to the container are not lost. 4. View Container (PS)

# List all currently running container
$docker PS
# List all container
$docker ps-a
# List The most recently launched container
$docker PS -L


5. Save 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 container can be run the next time you save the latest state.

# Save changes to the container; -A,--author= "" author; -M,--message= "" Commit message
$docker commit ID New_image_name

Note:image equivalent to the class, container equivalent to the instance, but you can dynamically install new software to the instance, and then the container with a commit command to solidify 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 individual containers;-F,--force=false;-L,--link=false remove the Specifi Ed Link and not the underlying container; 
-V,--volumes=false Remove The volumes associated to the container $docker RM name/id # Stop, start, kill a container $docker stop name/id $docker start name/id $docker kill Name/id # to fetch logs from a container; -F,--follow=false follow log output; -T,--timestamps=false Show timestamps $docker logs name/id # Lists the changed files or directories in a container, the list will show three events, a added, D deleted, C changed $docke R diff Name/id # shows the process information inside a running container $docker top NAME/ID # Copy files/directories from the container to a local path $docker CP Name:/container_path To_path $doc Ker CP Id:/container_path To_path # restarts a running container; -T,--time=10 number of seconds to try to stop for before killing the container, default=10 $docker Restart Name/id # attached to A running container above; --no-stdin=false does not attach stdin; --sig-proxy=true proxify all received signal to the process $docker attach ID 

The Note: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 from a container, from the ctrl-c.


7. Save and load the image (save, load)

When you need to migrate a mirror on one machine to another machine, you need to save the image and load the image.

# Save the image to a tar package; -O,--output= "" Write to a file
$docker save Image_name-o file_path
# Load a tar package format image;-I,--input= "" Read from A Tar archive file
$docker load-i file_path

# Machine A
$docker save image_name >/home/save.tar
# Use SCP to save . Tar to Machine B, then:
$docker Load 


8. Login to Registry server (login)

# Login to Registry server; -E,--email= "" email; -P,--password= "" password; -U,--username= "" Username
$docker Login


9. Publish image (push)

# Publish Docker image
$docker push new_image_name

10. Build a container based on the Dockerfile

#build--no-cache=false do no use
      cache when building the image
      -Q,--quiet=false suppress the verbose output gen  Erated by the containers
      --rm=true Remove Intermediate containers after a successful build
      -T,--tag= "" Repository Name (and optionally a tag) to being applied to the resulting image in case of success
$docker build-t image_name Docke Rfile_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.