Common commands

1
2
3
4
5
6
7
8
docker info #View local docker information
docker search openresty #Search for remote image warehouse
docker images #View the current system image warehouse image
docker ps #View the currently running container
docker pull centos #Get the remote image, the default tag is not specified, which is the latest
docker container run -p 8000:80 --rm -t -i centos:latest /bin/bash #-p maps the container port 80 to the node node8000 port, --rm terminates and deletes the container, which is suitable for temporary debugging, the -t option allows Docker to allocate a pseudo-terminal (pseudo-tty) and bind it to the standard input of the container, and -i keeps the standard input of the container open
docker container exec -i -t b5d7bad57561 /bin/bash #Enter the running container
docker rmi $(docker images -f "dangling=true" -q) #Batch delete invalid none images

Import and export images

1
2
3
docker save -o centos7.tar centos #Export image
docker load < centos7.tar #Import image (standard stream loading, including raw data such as tags)
docker load --input centos7.tar #Read image from tarball (non-standard loading)

Import and export container

1
2
3
4
5
6
docker ps #Default display of currently running containers
docker ps -a #View all containers including those that have been stopped
docker ps -l #Display the latest started container (including stopped ones)

docker export 5a80afa126ba > centos7.5a80afa126ba.tar #Export container snapshot
docker import 5a80afa126ba > centos7.5a80afa126ba.tar #Import from container snapshot file to image repository

Note: Users can use docker load to import image storage files to the local image repository, or use docker import to import a container snapshot to the local image repository. The difference between the two is that the container snapshot file will discard all historical records and metadata information (that is, only save the snapshot state of the container at that time), while the image storage file will save the complete record and the volume is also large. In addition, metadata information such as labels can be re-specified when importing from a container snapshot file.

Delete image or container

1
2
3
4
5
6
docker rmi jdeathe/centos-ssh #Delete local image
or
docker image rm jdeathe/centos-ssh #Delete local image
docker rm dbd4d83097f5 #Delete local container
or
docker container rm dbd4d83097f5 #Delete local container

Shut down and restart container

1
2
docker container kill dbd4d83097f5 #Shut down the running container
docker container restart dbd4d83097f5 #Restart container

Build image

1
2
docker image build . #Build image based on current directory dockerfile
docker image build -t cm-navigation:v0.0.1 . #Build image based on current directory dockerfile and tag