二、docker常用命令
docker的几大核心组件是镜像、容器、仓库、网络和存储。那今天学习一下对这几大组件操作的常用命令。其实docker的命令都有一个规律,对镜像操作用docker image,对容器操作用docker container,对卷操作用docker volume,对网络操作用docker network,并用--help查看具体的参数。
docker image
[root@docker-1-26 ~]# docker image --help Usage: docker image COMMAND Manage images #用于管理镜像 Commands: build Build an image from a Dockerfile #由docker文件构建一个镜像,用法:Usage: docker image build [OPTIONS] PATH | URL | - history Show the history of an image #查看镜像的历史, import Import the contents from a tarball to create a filesystem image #这个基本不用 inspect Display detailed information on one or more images #查看镜像的详细信息。用法:Usage: docker image inspect [OPTIONS] IMAGE [IMAGE...] load Load an image from a tar archive or STDIN #由tar文件生成一个镜像,同:docker load,用法:Usage: docker image load [OPTIONS];-i:由tar文件生成;-q:quiet ls List image #查看镜像列表,简写docker images。 prune Remove unused images #删除没用的镜像,这个也没啥用 pull Pull an image or a repository from a registry #从仓库中拉去一个镜像,Usage: docker image pull [OPTIONS] NAME[:TAG|@DIGEST] push Push an image or a repository to a registry #上传镜像到仓库中去,Usage: docker image push [OPTIONS] NAME[:TAG] rm Remove one or more images #删除一个镜像 save Save one or more images to a tar archive (streamed to STDOUT by default) #将镜像保存为tar格式 tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE #给某一镜像打一个tag Run 'docker image COMMAND --help' for more information on a command.
docker container
[root@docker-1-26 ~]# docker container --help Usage: docker container COMMAND Manage containers #用于管理容器 Commands: attach Attach local standard input, output, and error streams to a running container commit Create a new image from a container's changes #对镜像进行修改后,确认,并创建一个新镜像 cp Copy files/folders between a container and the local filesystem #在容器和本地文件系统间复制文件(夹),同docker cp, create Create a new container #创建一个新容器 diff Inspect changes to files or directories on a container's filesystem exec Run a command in a running container #在一个运行容器中运行命令,通常会带上“-i”“-t”,分别表示 export Export a container's filesystem as a tar archive inspect Display detailed information on one or more containers #查看容器的详细信息 kill Kill one or more running containers #杀死正在运行中的容器 logs Fetch the logs of a container #fetch:提取,提取容器中的日志 ls List containers #查看容器列表 pause Pause all processes within one or more containers #暂停容器服务,UNpause激活容器 port List port mappings or a specific mapping for the container #查看容器的端口映射情况 prune Remove all stopped containers #删除所有没有运行的容器,禁用 rename Rename a container #重命名容器 restart Restart one or more containers #重启某一个容器 rm Remove one or more containers #销毁一个容器 run Run a command in a new container #创建并运行一个容器,并运行命令行,同docker run,“-d”:后台,“-p”:端口映射,Usage: docker container run [OPTIONS] IMAGE [COMMAND] [ARG...] start Start one or more stopped containers #开启处于stop停止状态的容器 stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers #停止正在运行的容器 top Display the running processes of a container #查看容器的高消耗进程 unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes Run 'docker container COMMAND --help' for more information on a command.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言