1. Mirroring operations
1. List mirrors
View locally owned mirrors
$ docker images
Copy the code
or
$ docker image ls
Copy the code
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 9f38484d220f 2 days ago 202MB redis latest 0f88f9be5839 11 days ago 95MB Hello - World latest FCE289e99eb9 2 months ago 1.84kBCopy the code
2. Search for images
For example, query an Nginx image
$ docker search nginx
Copy the code
Output:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 11081 [OK] jwilder/nginx-proxy Automated Nginx Reverse Proxy for Docker Con... 1562 [OK] richarvey/ nginx-fpm capable of running nginx + php-fpm capable of... 690 [OK]Copy the code
3. Download the image
Pulling nginx is commonly referred to as pulling a pull image
$ docker pull nginx
Copy the code
4. Import/export images
Export nginx image, tar file if there is no path, the exported file is in the current directory
$ docker save nginx > nginx.tar
Copy the code
Import an Nginx image
$ docker load < nginx.tar
Copy the code
5. Delete the mirror
$ docker rmi nginx
Copy the code
Container operation
1. List containers
Lists running containers
$ docker ps
Copy the code
A container that lists all states, both running and stopped
$ docker ps -a
Copy the code
2. Create and start the container
Load an image into a container, such as a centos image
$ docker run -i -t centos /bin/bash
Copy the code
-t indicates that after the container is started, a pseudo-terminal /bin/bash is allocated to indicate the program to be run
Once started, you can press CTRL + P + Q to make the container run in the background
3. Enter the container
Enter the running CONTAINER, where a00AA07536CF is the CONTAINER ID (CONTAINER ID)
$ docker attach a00aa07536cf
Copy the code
You can customize a name
$ docker rename modest_goldberg my_centos
Copy the code
Then run it directly using the name
$ docker attach my_centos
Copy the code
4. Run the command
The arguments are the same as the run command
$ docker exec -it 280edfce7598 /bin/bash
Copy the code
-t indicates that after the container is started, a pseudo-terminal /bin/bash is allocated to indicate the program to be run
5. Stop the container
$ docker stop a00aa07536cf
Copy the code
6. Terminate the container
Forced out of
$ docker kill a00aa07536cf
Copy the code
7. Start the container
$ docker start a00aa07536cf
Copy the code
8. Restart the container
$ docker restart a00aa07536cf
Copy the code
9. Delete the container
To stop the container before deleting it, run the stop and kill commands
$ docker rm a00aa07536cf
Copy the code
Import/export containers
Export containers to generate container packages
$ docker export 3ae8f1fc3bfe > centos.tar
Copy the code
Zqyu /centos: Latest indicates the image name and version
$ docker import centos.tar zqyu/centos:latest
Copy the code
Native operation that generates images directly from the container
$ docker commit 3ae8f1fc3bfe zqyu/centos:latest
Copy the code