1. Details of docker common commands
1.1 docker info
Containers: 3 Number of containers Running: 2 Number of containers running Paused: 0 Suspended docker Number Stopped: 1 Stopped docker Number Images: 15 Mirror number Server Version: 17.03.3-ce docker Edition Storage Driver: overlay Storage driver format Backing Filesystem: xfs File system format Supports d_type: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 6c463891b1ad274d505ae3bb738e530d1df2b3c7 runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe init version: 949e6fa Security Options: seccomp Profile: default Kernel Version: 3.10.0-1062.9.1.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 3.692 GiB Name: centos7.clone ID: SSBJ:TBZ7:GG4Q:AWRB:OVNT:OZYW:CY7U:KZO4:YPX3:ENXW:WNDU:PIJ5 Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false Insecure Registries: 192.168.40.101:5000 127.0.0.0/8 Registry Mirrors: https://registry.docker-cn.com https://z53f46dz.mirror.aliyuncs.com Live Restore Enabled: false
docker info lists details about docker
1.2 Docker search
This command is used to search image. Search image from the registered image website
example:
docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 12690 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 1742 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 757 [OK] linuxserver/nginx An Nginx container, brought to you by Linu... 92 bitnami/nginx Bitnami nginx Docker Image 75 [OK] tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rt... 63 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ... 42 nginxdemos/hello NGINX webserver that serves a simple page ... 37 [OK] jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 35 [OK] nginx/unit NGINX Unit is a dynamic web and applicatio... 34 nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 25 privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & ... 21 [OK] schmunk42/nginx-redirect A very simple container to redirect HTTP t... 18 [OK] nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 13 blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 13 [OK] centos/nginx-18-centos7 Platform for running nginx 1.8 or building... 12 centos/nginx-112-centos7 Platform for running nginx 1.12 or buildin... 12 raulr/nginx-wordpress Nginx front-end for the official wordpress... 12 [OK] nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 9 sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats... 7 [OK] mailu/nginx Mailu nginx frontend 5 [OK] bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Con... 4 [OK] ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK] wodby/nginx Generic nginx 0 [OK] centos/nginx-110-centos7 Platform for running nginx 1.10 or buildin... 0
In this way, you can search the image of nginx and download it on the image website
1.3 Docker pull Download Image
docker pull image name: tag
This command is to download the image from the image website to the local. If no tag is added, the final version will be downloaded by default.
example:
docker pull mysql
1.4 Docker images viewing local images
docker images is to view the images that have been downloaded locally
example:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.40.101:5000/centos-jdk v1.8 b3e67747f09f 12 days ago 1.42 GB centos-jdk v1.8 b3e67747f09f 12 days ago 1.42 GB c-mysql 5.1 bbd4d86f1341 12 days ago 776 MB nginx latest 2073e0bcb60e 3 weeks ago 127 MB mysql 5.7 c4f186b9e038 3 weeks ago 435 MB registry latest 708bc6af7e5e 4 weeks ago 25.7 MB wordpress latest a9f43b7c47db 2 months ago 539 MB mariadb latest 2f11cf2ec189 2 months ago 355 MB tomcat latest 6fa48e047721 2 months ago 507 MB mysql latest d435eee2caa5 3 months ago 456 MB centos 6.8 82f3b5f3c58f 11 months ago 195 MB hello-world latest fce289e99eb9 13 months ago 1.84 kB hub.c.163.com/public/centos 6.7-tools b2ab0ed558bb 3 years ago 602 MB
1.5 Docker rmi delete image
docker rmi image name: tag / ID
To delete an image, add the image tag or delete it directly using the image ID. if the image is referenced by a running container, deletion is not allowed.
example:
docker rmi mysql:5.7
Untagged: nginx:latest Untagged: nginx@sha256:ad5552c786f128e389a0263104ae39f3d3c7895579d45ae716f528185b36bc6f Deleted: sha256:2073e0bcb60ee98548d313ead5eacbfe16d9054f8800a32bedd859922a99a6e1 Deleted: sha256:a3136fbf38691346715cac8360bcdfca0fff812cede416469653670f04e2cab0 Deleted: sha256:99360ffcb2da18fd9ede194efaf5d4b90e7aee99f45737e918113e6833dcf278 Deleted: sha256:488dfecc21b1bc607e09368d2791cb784cf8c4ec5c05d2952b045b3e0f8cc01e
1.6 Docker ps viewing container
docker ps -a view all containers, both running and stopped
docker ps -s view running containers
docker ps -q view container ID
example:
docker ps -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 4d3e93e474af wordpress:latest "docker-entrypoint..." 31 minutes ago Up 31 minutes 0.0.0.0:8080->80/tcp root_wordpress_1 95 B (virtual 539 MB) 93f4a5dbaa96 mysql:5.7 "docker-entrypoint..." 31 minutes ago Up 31 minutes 3306/tcp, 33060/tcp root_wpdb_1 4 B (virtual 435 MB)
1.7 Docker run create a container
docker run [– option] create a container
example:
docker run --name docker-mysql5.7 -e MYSQL_ROOT_PASSWORD=root -p 3307:3306 -d mysql:5.7
1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671
The ID of the container will be returned after creation
When creating a container, you can add many parameters, that is, configure the running state of the container at the beginning of creation.
[optional]
– restart always after creating the container, you can start the container with the start of the docker process in the future, which is similar to the meaning of booting and booting
-h host name set the container host name. If not set, it is the container ID by default
– dns xxx.xxx.xxx.xxx specifies the dns resolution service address to the container, which can provide the container with an Internet connection environment
– add host hostname: IP adds host mapping to the container
- rm will be deleted when the container stops after this parameter is added. If stop is not added, it can still exist
1.8 Docker start/stop
docker start starts a container that has been created
docker stop stops a running container, plus - f forces the deletion of the running container
1.9 ID number of container
Each container will be assigned an ID as the index. The ID is 128 bits in total, but usually only 12 bits are displayed
If you want to view the complete ID, you can use docker PS -- no TRUNC
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671 mysql:5.7 "docker-entrypoint.sh mysqld" 49 seconds ago Up 48 seconds 33060/tcp, 0.0.0.0:3308->3306/tcp docker-mysql5.7-2 76ad9d4dc133895f0a9f0b6742e13d31a35fc47c3aae150316ce5700407b824b mysql:5.7 "docker-entrypoint.sh mysqld" 2 minutes ago Up 2 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp docker-mysql5.7 4d3e93e474af950aa2490bc6eda30a0c5df93992e2602c1f9ca0d0446d25a53d wordpress:latest "docker-entrypoint.sh apache2-foreground" 39 minutes ago Up 39 minutes 0.0.0.0:8080->80/tcp root_wordpress_1 93f4a5dbaa969b5c3ea4eb0a0abb5a2769137588207e310266c6546ba34e9736 mysql:5.7 "docker-entrypoint.sh mysqld" 39 minutes ago Up 39 minutes 3306/tcp, 33060/tcp root_wpdb_1
1.10 Docker inspect
Docker inspect is to view container details
example:
docker inpect mysql:5.7
[ { "Id": "1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671", "Created": "2020-02-23T10:34:52.321913757Z", "Path": "docker-entrypoint.sh", "Args": [ "mysqld" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 4040, "ExitCode": 0, "Error": "", "StartedAt": "2020-02-23T10:34:52.528995606Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:c4f186b9e038c856c5fb5f6b27ca106db3cc064594b7e5706d0350a3ab6220db", "ResolvConfPath": "/var/lib/docker/containers/1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671/resolv.conf", "HostnamePath": "/var/lib/docker/containers/1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671/hostname", "HostsPath": "/var/lib/docker/containers/1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671/hosts", "LogPath": "/var/lib/docker/containers/1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671/1ab8771b067ece7f838fffb26a6eca59371fb51dd7fca95cc2443f93aa4e3671-json.log", "Name": "/docker-mysql5.7-2", "RestartCount": 0, "Driver": "overlay", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, ...... ]
1.11 Docker logs viewing container logs
docker logs container
example:
docker logs docker-mysql5.7
2020-02-23 10:32:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started. 2020-02-23 10:32:54+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2020-02-23 10:32:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started. 2020-02-23T10:32:54.760763Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-02-23 10:32:54+00:00 [Note] [Entrypoint]: Initializing database files 2020-02-23T10:32:54.845726Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-02-23T10:32:54.860056Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-02-23T10:32:54.914339Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d9fc92fe-5627-11ea-98e4-0242ac110002. 2020-02-23T10:32:54.915075Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-02-23T10:32:56.027454Z 0 [Warning] CA certificate ca.pem is self signed.
1.12 Docker stats view resource usage of container
dokcer stats container name view the resources consumed by the container
example:
docker stats docker-mysql5.7
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS docker-mysql5.7 0.03% 398.8 MiB / 3.692 GiB 10.55% 3.26 kB / 4.41 kB 0 B / 583 MB 29
This display is refreshed in real time, similar to the top command of the host to check the memory usage.
1.13 interaction between docker exec and container
docker exec container name
example:
docker exec -it container / bin/bash
Enter the container environment through this command, which is the same as the command line operation of the host.