1.Docker 命令列表
[root@host1 ~]# docker
Usage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersCommon Commands:run Create and run a new container from an imageexec Execute a command in a running containerps List containersbuild Build an image from a Dockerfilebake Build from a filepull Download an image from a registrypush Upload an image to a registryimages List imageslogin Authenticate to a registrylogout Log out from a registrysearch Search Docker Hub for imagesversion Show the Docker version informationinfo Display system-wide informationManagement Commands:builder Manage buildsbuildx* Docker Buildxcompose* Docker Composecontainer Manage containerscontext Manage contextsimage Manage imagesmanifest Manage Docker image manifests and manifest listsnetwork Manage networksplugin Manage pluginssystem Manage Dockertrust Manage trust on Docker imagesvolume Manage volumesSwarm Commands:swarm Manage SwarmCommands:attach Attach local standard input, output, and error streams to a running containercommit Create a new image from a container's changescp Copy files/folders between a container and the local filesystemcreate Create a new containerdiff Inspect changes to files or directories on a container's filesystemevents Get real time events from the serverexport Export a container's filesystem as a tar archivehistory Show the history of an imageimport Import the contents from a tarball to create a filesystem imageinspect Return low-level information on Docker objectskill Kill one or more running containersload Load an image from a tar archive or STDINlogs Fetch the logs of a containerpause Pause all processes within one or more containersport List port mappings or a specific mapping for the containerrename Rename a containerrestart Restart one or more containersrm Remove one or more containersrmi Remove one or more imagessave Save one or more images to a tar archive (streamed to STDOUT by default)start Start one or more stopped containersstats Display a live stream of container(s) resource usage statisticsstop Stop one or more running containerstag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEtop Display the running processes of a containerunpause Unpause all processes within one or more containersupdate Update configuration of one or more containerswait Block until one or more containers stop, then print their exit codesGlobal Options:--config string Location of client config files (default "/root/.docker")-c, --context string Name of the context to use to connect to the daemon (overridesDOCKER_HOST env var and default context set with "docker context use")-D, --debug Enable debug mode-H, --host string Daemon socket to connect to-l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal")(default "info")--tls Use TLS; implied by --tlsverify--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")--tlskey string Path to TLS key file (default "/root/.docker/key.pem")--tlsverify Use TLS and verify the remote-v, --version Print version information and quitRun 'docker COMMAND --help' for more information on a command.
#提示用命令查看某條具體子命令的幫助信息。For more help on how to use Docker, head to https://docs.docker.com/go/guides/
例如,查看 tag 子命令的幫助信息
[root@host1 ~]# docker tag --help
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEAliases:docker image tag, docker tag
2.運行一個容器(以 docker run 命令為例)
[root@host1 ~]# docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
76249c7cd503: Pull complete
Digest: sha256:9cbed754112939e914291337b5e554b07ad7c392491dba6daf25eef1332a22e8
Status: Downloaded newer image for ubuntu:latest
root@49e91767b48d:/# ls #列出當前目錄內容
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@49e91767b48d:/# uname -a #顯示當前操作系統內核信息
Linux 49e91767b48d 5.14.0-611.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 22 16:46:08 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
root@49e91767b48d:/# cat /etc/issue #查看當前操作系統發行版信息
Ubuntu 24.04.3 LTS \n \lroot@49e91767b48d:/# exit #結束,只停止不刪除
exit
[root@host1 ~]# docker ps -a #查看當前容器列表
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
49e91767b48d ubuntu "/bin/bash" About a minute ago Exited (0) 21 seconds ago frosty_lichterman
38b001022f7a hello-world "/hello" 29 minutes ago Exited (0) 29 minutes ago intelligent_brahmagupta