Docker Usage Tutorials (2) Common commands

Source: Internet
Author: User
Tags docker ps docker cp docker run

1. View Docker information (version, info)

# View the 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 mirrors; -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 mirrors; -F,--force=false force; --no-prune=false do not delete untagged parents
$docker RMI Image_name

# shows the history of a mirror; --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 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 and output "Hello word"
$docker run image_name echo "Hello word"

# Interactive entry into 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: 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 the 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. Operation of the container (RM, stop, start, Kill, logs, diff, top, CP, restart, attach)

# Remove All containers
$docker RM ' Docker ps-a-Q '
$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 a container
$docker Stop Name/id
$docker Start name/id
$docker Kill Name/id

# take logs from a container; -F,--follow=false follow log output; -T,--timestamps=false Show timestamps
$docker logs Name/id

# lists the files or directories that have been changed in a container, the list will show three events, a added, D deleted, C changed
$docker 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
$docker CP Id:/container_path To_path

# reboot 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 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 an file
$docker Save Image_name-o File_path
# load an image in a 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 SCP to copy the 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 a Docker image
$docker Push New_image_name


10. Build a container based on the Dockerfile

#build
--no-cache=false don't 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 being applied to the resulting image in case of success
$docker build-t image_name Dockerfile_path

Docker Usage Tutorials (2) Common commands

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.