What is Docker?
Docker is an open-source engine that can easily create a lightweight, portable, self-contained container for any application. Developers compiling tests on notebooks can be deployed in bulk in a production environment, including VMS, bare metal, OpenStack clusters, and other basic application platforms.
Docker is typically used in the following scenarios:
Automated packaging and publishing of Web applications;
Automated testing and continuous integration, release;
Deployment and tuning of databases or other background applications in a service-oriented environment;
Build your own PAAs environment from scratch or by extending existing openshift or cloud foundry platforms.
Let me introduce you to the following common commands
Docker Common Commands
Operation Container
Start container
Start the container and start Bash (interactive):
$docker run-i-T <image_name/continar_id>/bin/bash
Start the container to run later (more general way):
$docker run-d-it image_name
PS: The image_name here contains the tag:hello.demo.kdemo:v1.0
Attach to 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, to write a indocker.sh:
$cat indocker.sh
Docker exec-t-i $1/bin/bash
# View the container ID that needs to be attached
$docker PS | less-s
CONTAINER ID image< c6/>9cf7b563f689 hello.demo.kdemo:v160525.202747
$./indocker.sh 9cf7b563f689
To view the container log
To view the container log
Docker logs <id/container_name>
View log output in real time
Docker logs-f <id/container_name> (similar to tail-f) (with time stamp-T)
View Container
Lists all currently running container
$docker PS
List all running container in one row (very clear when containers are more)
$docker PS | Less-s
List all the container
$docker ps-a
List the most recently started container
$docker ps-l
Shows the process information in a running container
$docker Top Name/id
Look inside the container for details:
$docker Inspect <id/container_name>
To install 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 the interactive mode, requiring the user to enter a command to confirm, but in a Docker environment it is not possible to respond to this interaction. After the Apt-get command has finished executing, the container stops, but changes to the container are not lost.
Copy files/directories from the container to a local path
$docker CP Name:/container_path To_path
$docker CP Id:/container_path To_path
Save modifications 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 you can run the container the next time from the last state you saved.
$docker Commit ID New_image_name
Note: image is equivalent to a class, container is equivalent to an instance, but you can dynamically install new software to the instance, and then the container is solidified into an image with a commit command.
Delete a single container
$docker RM name/id
-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, reboot a container
$docker Stop name/id
$docker start name/id
$docker kill name/id
$docker restart Name/id
Operation 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 image from Dockerhub
$docker Search Image_name
Download image
$docker Pull Image_name
Deletes one or more mirrors;
$docker RMI Image_name
-f,–force=false Force; –no-prune=false do not delete untagged parents
Displays the history of a mirror;
$docker History Image_name
Publishing Docker Mirrors
$docker Push New_image_name
PS: To publish to a mirror in a private registry, you need to bring a registry domain name in the mirror name (if not 80 ports and you need to bring the top number) for example:
$docker Push dockerhub.yourdomain.com:443/hello.demo.kdemo:v1.0
Pull Docker Mirror
$docker Pull Image_name
Network operations
View the DOCKER0 Network (operations on the host)
$ip a show Docker0
To view the IP address of a 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 basic information
View Docker version
$docker version
View information about the Docker system
$docker Info
Thank you for reading, I hope to help you, thank you for your support for this site!