Help command
- docker version
- Displays the version information of docker
- docker info
- Show docker details
- docker command -- help
- View the help documentation for the command
Mirror command
- docker images
- View all local mirrors
- parameter
- -a displays all mirrors
- -q display id only
- docker search
- You can also go to the docker hub to search for images
- parameter
- –filter
- docker search mysql --filter=STARS=3000 only search for stars above 3000
- –filter
- docker pull image
- Download the image. You can keep up with the version later. docker pull image: tag. If you don't write, the default is latest, that is, the latest
- Layered download, the core federated file system of docker image, will be introduced later
- docker rmi image id
- To delete an image, rm means to delete an image
- Delete all mirrors
- docker rmi $(docker images -aq)
Container command
- docker run [optional parameter] image
- Start container
- parameter
- – name = "name" container name
- -d operate in the background mode, similar to nohub
- -it runs interactively, entering the container to view the content
- -p specifies the port of the container
- -p ip: host port: container port
- -p host port: container port (common)
- -p container port
- -P randomly assigned port
- test
# Enter the container interactively fujunhua@fujunhuadeMacBook-Air ~ % docker run -it centos /bin/bash [root@c76e60706682 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@c76e60706682 /]#
- exit
- Exit container command
- Exit without stopping: ctrl + p +q
- docker ps
- View running containers
- -a parameter allows you to view the history of previous runs + all currently running containers
- -N displays the recently created container - n=1 displays only the latest one
- -q displays the container number
- docker rm container id
- Delete all containers docker rm -f $(docker ps -aq)
- Note: if you want to delete a running container, you need to add the parameter - f
- docker start container id
- Start container
- docker restart container id
- Restart container
- docker stop container id
- Stop running id
- docker kill container id
- Force stop container
Other commonly used commands
- docker logs [optional parameter] container id
- view log
- -tf tracks data and displays a timestamp
- – tail number displays the number of data in the tail
- docker top container id
- View the process information inside the container
- Enter a running container
- Mode 1
- docker exec container id
- Mode II
- docker attach container id
- difference
- In mode 1, a new client will be opened, and in mode 2, it will enter the currently executing terminal
- Mode 1
- Copy files from the container to the host
- docker cp container di: host path
- docker inspect container id
- View metadata for container
[ { "Id": "1034277f7d1e825bbed15173a441ba63f3bfcacc9263be3c793955ba1bdfbff4", "Created": "2022-01-16T07:53:58.7423733Z", "Path": "/bin/bash", "Args": [ "-c", "while true;do echo hello;sleep 1;done" ], "State": { "Status": "exited", "Running": false, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 0, "ExitCode": 137, "Error": "", "StartedAt": "2022-01-16T07:53:59.2984293Z", "FinishedAt": "2022-01-16T07:55:13.3905686Z" }, "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6", "ResolvConfPath": "/var/lib/docker/containers/1034277f7d1e825bbed15173a441ba63f3bfcacc9263be3c793955ba1bdfbff4/resolv.conf", "HostnamePath": "/var/lib/docker/containers/1034277f7d1e825bbed15173a441ba63f3bfcacc9263be3c793955ba1bdfbff4/hostname", "HostsPath": "/var/lib/docker/containers/1034277f7d1e825bbed15173a441ba63f3bfcacc9263be3c793955ba1bdfbff4/hosts", "LogPath": "/var/lib/docker/containers/1034277f7d1e825bbed15173a441ba63f3bfcacc9263be3c793955ba1bdfbff4/1034277f7d1e825bbed15173a441ba63f3bfcacc9263be3c793955ba1bdfbff4-json.log", "Name": "/condescending_wu", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "CgroupnsMode": "private", "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "GroupAdd": null, "IpcMode": "private", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": null, "UTSMode": "", "UsernsMode": "", "ShmSize": 67108864, "Runtime": "runc", "ConsoleSize": [ 0, 0 ], "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": [], "BlkioDeviceReadBps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteIOps": null, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DeviceCgroupRules": null, "DeviceRequests": null, "KernelMemory": 0, "KernelMemoryTCP": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": null, "PidsLimit": null, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0, "MaskedPaths": [ "/proc/asound", "/proc/acpi", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/proc/scsi", "/sys/firmware" ], "ReadonlyPaths": [ "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] }, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/532d282bceb5837f369d07e93049428b6186522d7fbcc14fcd484e628bf32eac-init/diff:/var/lib/docker/overlay2/e02ce3392809941fc8f32a20554f285a62341cb1c417b3691f9fa3fef4fbe6bf/diff", "MergedDir": "/var/lib/docker/overlay2/532d282bceb5837f369d07e93049428b6186522d7fbcc14fcd484e628bf32eac/merged", "UpperDir": "/var/lib/docker/overlay2/532d282bceb5837f369d07e93049428b6186522d7fbcc14fcd484e628bf32eac/diff", "WorkDir": "/var/lib/docker/overlay2/532d282bceb5837f369d07e93049428b6186522d7fbcc14fcd484e628bf32eac/work" }, "Name": "overlay2" }, "Mounts": [], "Config": { "Hostname": "1034277f7d1e", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/bash", "-c", "while true;do echo hello;sleep 1;done" ], "Image": "centos", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20210915", "org.label-schema.license": "GPLv2", "org.label-schema.name": "CentOS Base Image", "org.label-schema.schema-version": "1.0", "org.label-schema.vendor": "CentOS" } }, "NetworkSettings": { "Bridge": "", "SandboxID": "8972234fb6a32e394f62df5fa6f360e7fde0ef8dc16604e3c3669adc67329d78", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/8972234fb6a3", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "92c36ac958105306e65d52f80c779b6b856913108b786248f0c97a4750ccab9f", "EndpointID": "", "Gateway": "", "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "", "DriverOpts": null } } } } ]
summary
![image.png](https://img-blog.csdnimg.cn/img_convert/a2af10834f3294af389e878c98c54ce1.png#clientId=uf85421a1-f985-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=557&id=u54549c33&margin=[object Object]&name=image.png&originHeight=557&originWidth=777&originalType=binary&ratio=1&rotation=0&showTitle=false&size=313971&status=done&style=none&taskId=uda0277ff-e1c2-48fa-9590-0fca9ac46c4&title=&width=777)