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
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
$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
$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
$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
$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
$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
$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