Docker is an improved container technology. The specific "improvement" is that Docker introduces an image for the container, so that the container can be created from predefined templates (images), and the template is hierarchical.
Docker features:
- Lightweight, which is reflected in small memory consumption and high density
- Fast, millisecond start
- Isolation, sandbox technology is more like virtual machine
Docker installation
Docker is very simple to install and supports all current mainstream operating systems, from Mac to Windows to various Linux distributions
Specific reference: Docker installation
Common Docker Commands
Container related operations
Docker create # Create a container but do not start it
Docker run # Create and start a container
Docker stop # Stop the container and send the signal SIGTERM
Docker start # Start a stopped container
Docker restart # Restart a container
Docker rm # Delete a container
Docker kill # Send a signal to the container. The default is SIGKILL
Docker attach # Connect (enter) to a running container
Docker wait # Block to a container until the container stops running
Get container related information
Docker ps # Display containers in Up status
Docker ps - a # Display all containers, including those in operation (Up) and those exiting (Exited)
Docker inspect # Go deep into the container to obtain all the container information
Docker logs # View container logs (stdout/stderr)
Docker events # Get real-time events of the docker server
Docker port # Display the port mapping of the container
Docker top # Display the process information of the container
Docker diff # Display the changes of the container file system
Export Container
Docker cp # Copy files or directories from the container
Docker export # Export the entire file system of the container as a tar package without layers, tags, and other information
implement
Docker exec # Execute a command in the container, and you can execute bash to enter interactive
Mirror operation
Docker images # Display a list of all local images
Docker import # Create an image from a tar package, often used in combination with export
Docker build # Use Dockerfile to create images (recommended)
Docker commit # Create an image from the container
Docker rmi # Delete an image
Docker load # Create an image from a tar package and use it with save
Docker save # Save an image as a tar package with layers and tag information
Docker history # Display the history command of generating an image
Docker tag # Create an alias for the image
Image warehouse (registry) operation
Docker login # Log in to a registry
Docker search # Search image from registry warehouse
Docker pull # Download image from warehouse to local
Docker push # Push an image into the registry warehouse
Obtain the container IP address (the container status must be Up)
docker inspect id | grep IPAddress | cut -d '"' -f 4
Get port mapping
docker inspect -f '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' id
Get environment variables
docker exec container_id env
Kill all running containers
docker kill $(docker ps -q)
Delete the old (created a week ago) container
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs docker rm
Delete a stopped container
docker rm docker ps -a -q
Delete all images, be careful
docker rmi $(docker images -q)
Reference link:
https://blog.csphere.cn/archives/22