Docker Common Commands

Source: Internet
Author: User
Tags docker ps docker cp

Docker Common Command Operations container start container
    • Start the container and start Bash (interactive mode):
$docker run-i-T <image_name/continar_id>/bin/bash
    • Start the container to run later (in a more general way):
$docker run-d-it  image_name

PS: The image_name here contains the tag:hello.demo.kdemo:v1.0

Attaching to a container
    • Attaching to a running container
Docker Attach <id, container_name>
    • Go inside a running container and run bash at the same time (better than attach)
Docker exec-t-I <id/container_name>  /bin/bash

Ps:docker exec is so useful that we usually encapsulate it as a script and put it in a global callable place, for example, it can be written as a indocker.sh:

$cat indocker.sh Docker exec-t-I $1/bin/bash# see the containers you need to attach Id$docker PS | Less-scontainer ID        IMAGE                                                 9cf7b563f689        
View Container Logs
    • View Container Logs
Docker logs <id/container_name>
    • View log output in real time
Docker logs-f <id/container_name> (similar to tail-f) (with timestamp-t)
View Container
    • List all currently running container
$docker PS
    • List all running container in one row (very clear when the container is many)
$docker PS | Less-s
    • List all the container
$docker ps-a  
    • List the most recently launched container
    • Displays the process information inside a running container
$docker Top Name/id  
    • View Container Internals Details:
$docker Inspect <id/container_name>
    • Installing a new program in a 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.

    • Copy files/directories from a container to a local path
$docker CP Name:/container_path To_path  $docker CP Id:/container_path To_path
    • Saving changes to a 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.
$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.

    • 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

    • Remove all containers
$docker RM ' Docker ps-a-Q '  
    • Stop, start, kill, restart a container
$docker Stop name/id  $docker start name/id  $docker kill name/id  $docker restart Name/id
Action Image
    • List Mirrors
$sudo Docker Images

-a,–all=false Show all images; –no-trunc=false Don ' t truncate output; -q,–quiet=false only show Numeric IDs

    • Retrieving an image from Dockerhub
$docker Search Image_name
    • Download image
$docker Pull Image_name
    • Delete one or more mirrors;
$docker RMI Image_name  

-f,–force=false Force; –no-prune=false do not delete untagged parents

    • Shows the history of a mirror;
$docker History Image_name
    • Publish a Docker image
$docker Push New_image_name

PS: To publish to the private registry in the Mirror, in the mirror name need to bring the registry domain name (if not 80 ports, and the need to bring the upper port number) such as:

$docker Push dockerhub.yourdomain.com:443/hello.demo.kdemo:v1.0
    • Pull Docker Image
$docker Pull Image_name
Network operation
    • View Docker0 Network (action on host)
$ip a show Docker0
    • View the IP address of the container
$docker inspect-f ' {{. Networksettings.ipaddress}} ' <id, container_name>

Attach to the inside of the container to view its internal IP:

$ip a show eth0
View Docker Basics View Docker version

$docker version

View information about the Docker system

$docker Info

Posted by: Big CC | 29may,2016 Blog: blog.me115.com [subscribe to]github: Big cc

Docker 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.