What is Docker
Not exactly, Docker is a lightweight virtual machine that packs executables and run environments into an image that runs in a container, but starts faster than a virtual machine and consumes less resources. This technique is primarily intended to address the issue of deployment environments.
Get image from remote repository
docker pull <image:[tag]>
An image of the same name can be tagged to differentiate the version. If you do not add tag, the default is latest
Container operation
Create container
docker run [options] <image> <cmd>
- -d daemon mode, running in the background
- --name set the name. It is better to set one, or in the stop, RM time to access through the ID, trouble
- --net networking mode, see after.
- --RM is deleted after container exits. Otherwise, the container will still exist in the "exited" state.
Container's name cannot be repeated.
Stop, start (only temporarily stop, not delete, can continue to run)
docker stop|start <container_id|container_name>
Delete
docker rm [-f] <container_id|container_name>
If you set a name when creating a container, you can access it by name and Support tab completion.
Show process
Docker's container does not automatically delete after exiting, but still exists in a stopped manner.
docker ps [options]
- -a displays all container. Otherwise, only the running container is displayed by default
- -Q displays only the ID. Otherwise the default display ID, name, corresponding image, startup time and other information
Clear
Docker does not have commands like clean, you can delete all container by itself.
docker rm -f $(docker ps -aq)
Delete all image
docker rmi $(docker images -q)
Networking mode
Docker supports multiple networking modes between host and container, one is the default mode, with Ifconfig you can see one more network interface, container open port is not accessible through the host IP. The other is the host mode (using the parameter--net=host), in this mode, container directly using the host's network stack, the port directly through the host external exposure.
Docker Beginner Notes