本文主要对Docker中常用的一些命令进行整理介绍。

1 帮助命令

docker version # 显示docker的版本信息
docker info #显示docker更加详细的一些信息,系统信息包含镜像和容器的数量
docker 命令 --help # 帮助命令

官方帮助文档的地址,链接:https://docs.docker.com/engine/reference/run/

2 镜像命令

docker images 查看本地主机上的所有的镜像

[root@ ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    bf756fb1ae65   15 months ago   13.3kB
'''
REPOSITORY    镜像的仓库源
TAG           镜像的标签
'''
#可选项
List imagesOptions:-a, --all             Show all images (default hides intermediate images)--digests         Show digests-f, --filter filter   Filter output based on conditions provided--format string   Pretty-print images using a Go template--no-trunc        Don't truncate output-q, --quiet           Only show image IDs

docker search 搜索镜像
也可以在docker hub上搜索

docker search [名字]
#可选项
--filter , -f       Filter output based on conditions provided
--format        Pretty-print search using a Go template
--limit 25  Max number of search results
--no-trunc      Don't truncate output

docker pull 下载镜像

docker pull [OPTIONS] NAME[:TAG|@DIGEST]
#可选项-a, --all-tags                Download all tagged images in the repository--disable-content-trust   Skip image verification (default true)--platform string         Set platform if server is multi-platform capable-q, --quiet                   Suppress verbose output
[root@iZ ~]# docker pull mysql
Using default tag: latest  #不写明tag的话默认下载最新版本的
latest: Pulling from library/mysql # 在下载的时候会使用分层下载的方式,是image的核心
# 分层的优势在于不同版本的镜像有时候部分分层是一样的,这样的话
# 就不需要进行重复的下载 对性能进行了优化
a076a628af6f: Pull complete
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1a8c919e89bf: Pull complete
9f3cf4bd1a07: Pull complete
80539cea118d: Pull complete
201b3cad54ce: Pull complete
944ba37e1c06: Pull complete
Digest: sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c # 签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest # 真实地址
# 使用pull的时候可以直接使用 docker pull 真实地址

docker rmi 删除镜像

[root@~]# docker rmi --helpUsage:  docker rmi [OPTIONS] IMAGE [IMAGE...]Remove one or more imagesOptions:-f, --force      Force removal of the image--no-prune   Do not delete untagged parents

3 容器命令

有了镜像才能够创建容器,这里使用pull命令下载一个centos镜像来测试学习。
新建容器启动

docker run 【参数】 images
#常用参数
--name=”name"     容器名字,用来区分容器
-d              后台方式运行
-it             使用交互方式运行,进入容器查看内容
-p              指定容器的端口 -p 8080-p   ip:主机端口:容器端口-p    主机端口:容器端口(最常用)-p   容器端口容器端口
-P              随机指定端口
#测试
[root@iZbxfZ ~]# docker run --name "ctos" -it centos /bin/bash
[root@0ea217478542 /]# exit # 退出

docker ps 列出正在运行的容器

[root@~]# docker ps --helpUsage:  docker ps [OPTIONS]List containersOptions:-a, --all             Show all containers (default shows just running)-f, --filter filter   Filter output based on conditions provided--format string   Pretty-print containers using a Go template-n, --last int        Show n last created containers (includes all states) (default -1)-l, --latest          Show the latest created container (includes all states)--no-trunc        Don't truncate output-q, --quiet           Only display container IDs-s, --size            Display total file sizes

退出容器

exit # 停止并退出容器
strl+p+q # 退出容器不停止

删除容器

docker rm 容器id                   #删除单个容器
docker rm -f $(docker images -aq) #删除所有的容器

启动和停止容器

docker start id
docker restart id
docker stop id
docker kill id

4 其他

后台启动容器

[root@~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@~]# docker run -d centos
884c6a2037b1e8554dcdd802301f594280416a741dc18e9a14b5cf3aca9e850a
[root@~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
"""
虽然设置了后台运行,但是centos还是停止了
docker后台运行的话需要有一个前台进程,docker发现没有应用就会自动停止
"""

查看日志
docker logs

Usage:  docker logs [OPTIONS] CONTAINERFetch the logs of a containerOptions:--details        Show extra details provided to logs-f, --follow         Follow log output--since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)-n, --tail string    Number of lines to show from the end of the logs (default "all")-t, --timestamps     Show timestamps--until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)

查看容器中的进程信息
docker top 【容器id】
查看镜像的元数据
docker inspect

[root@~]# docker inspect --helpUsage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]Return low-level information on Docker objectsOptions:-f, --format string   Format the output using the given Go template-s, --size            Display total file sizes if the type is container--type string     Return JSON for specified type

进入当前正在运行的容器
场景:进入后台运行的容器修改一些配置

方式一
docker exec -it 容器id bashshell
进入容器之后开启一个新的终端,可以在里面进行操作(常用)
方式二
docker attach 容器id
进入容器中正在执行的终端,不会启动新的进程

从容器内拷贝文件到主机
docker cp 容器id:容器内文件路径 主机路径
这个拷贝的过程是一个手动的过程 可以使用卷的技术来实现自动的同步

5 docker 命令汇总

Commands:attach      Attach local standard input, output, and error streams to a running containerbuild       Build an image from a Dockerfilecommit      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 serverexec        Run a command in a running containerexport      Export a container's filesystem as a tar archivehistory     Show the history of an imageimages      List imagesimport      Import the contents from a tarball to create a filesystem imageinfo        Display system-wide informationinspect     Return low-level information on Docker objectskill        Kill one or more running containersload        Load an image from a tar archive or STDINlogin       Log in to a Docker registrylogout      Log out from a Docker registrylogs        Fetch the logs of a containerpause       Pause all processes within one or more containersport        List port mappings or a specific mapping for the containerps          List containerspull        Pull an image or a repository from a registrypush        Push an image or a repository to a registryrename      Rename a containerrestart     Restart one or more containersrm          Remove one or more containersrmi         Remove one or more imagesrun         Run a command in a new containersave        Save one or more images to a tar archive (streamed to STDOUT by default)search      Search the Docker Hub for imagesstart       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 containersversion     Show the Docker version informationwait        Block until one or more containers stop, then print their exit codes

Docker系列(三)Docker的常用命令相关推荐

  1. Docker系列三~docker安装nginx

    Docker系列三 docker安装nginx 搜索nginx版本 docker search nginx 拉取nginx最新版本镜像 docker pull nginx:latest 查看本地镜像 ...

  2. Docker系列(二)-Dcoker的常用命令

    文章目录 帮助命令 镜像命令 查看本机镜像 搜索镜像 下载镜像 删除镜像 查看镜像的历史 容器命令 启动容器 查看运行容器 退出容器 删除容器 启动和停止容器 常用的其他命令 后台启动容器 查看日志 ...

  3. Docker系列 三. Docker安装mysql

    1.环境&工具: 阿里云轻量级服务器.centos7系统.FinalShell(其他连接客户端也可以) 2.安装mysql 2.1 获取mysql镜像 获取mysql镜像 2.2 下载最新my ...

  4. docker系列(三)docker三剑客之Compose

    docker-compose,快速对docker容器集群进行编排 Docker Compose 介绍 Docker-Compose 是 Docker 的一种编排服务,是一个用于在 Docker 上定义 ...

  5. Nginx教程系列三:Nginx常用命令

    文章目录 查看版本号 启动nginx 停止nginx 重新加载nginx 进入nginx目录 cd /usr/local/nginx/sbin/ 查看版本号 ./nginx -v 输出 nginx v ...

  6. docker 一起性重启所有镜像_docker系列四之docker镜像与容器的常用命令

    docker镜像与容器的常用命令 一.概述 docker的镜像于容器是docker中两个至关重要的概念,首先给各位读者解释一下笔者对于这两个概念的理解.镜像,我们从字面意思上看,镜子里成像,我们人站在 ...

  7. [跨平台系列三Docker篇]:ASP.NET Core应用

    如果你是老张的忠实读者的话,如果是从博客园就开始看我的文章的话,如果后期也一直看我公众号的话,应该就知道其实我一直在根据一条无形的教学线路来讲解的,,如果你真的是想好好学的话,请好好看看我之前的文章吧 ...

  8. Docker系列(二十一)——Docker实例三Docker安装Tomcat实例

    < Docker实例三Docker安装Tomcat实例 > 前言 在前面一篇文章种,完成了 < Docker安装Nginx实例 >,本篇将继续镜像安装教程,并完成Docker安 ...

  9. Docker系列五~docker安装php-fpm

    Docker系列五 docker安装php-fpm 访问PHP镜像库地址: https://hub.docker.com/_/php?tab=tags 选择合适的版本 php-fpm镜像主要是提供ph ...

  10. Docker系列一 ~docker的安装

    Docker系列一 docker安装 依照centos为例,Docker 官方建议要 CentOS7.0 及以上系统版本,在运行CentOS 6.5及以后版本时,需要内核版本>=2.6.32-4 ...

最新文章

  1. apache http配置https
  2. 如何对以破折号/连字符开头的字符串进行grep?
  3. 如何将系统退回上个版本Android,vivo NEX A降级教程,如何回退到旧版本系统的方法...
  4. 领域驱动设计(DDD):领域和子域
  5. org.xml.sax.SAXParseException: Failed to read schema document错误的完美解决方法 以及 Spring如何加载XSD文件
  6. mysql插入报主键冲突,解决方法主键索引重新排序
  7. mysql基本sql语句总结(一)
  8. 记一次线上Zabbix对Redis监控实录
  9. ELK 架构之 Elasticsearch 和 Kibana 安装配置
  10. 关于线段树套伸展树被卡常
  11. 怎样解决mysql最后一步提示未响应
  12. 解决Fedora14中文显示问题
  13. 0x80070057复制从服务器复制文件,解决win10更改用户文件夹提示0x80070057的方法
  14. TMS VCL UI包功能和特点
  15. GEE-Scholars MODIS地表温度LST时间变化趋势
  16. 我的世界服务器宝石系统指令,《我的世界》作弊码大全 MC当中所有的指令总汇...
  17. JWS实现WebService
  18. 如何下载腾讯课堂网页版的历史回放(电脑端)大多网页上的视频均可下载
  19. 手写Vue个人组件库——fl-Lazyimg 图片懒加载
  20. argparse.ArgumentError: argument --title: conflicting option string: --title

热门文章

  1. 审评(HelloWorld团队)
  2. 给宝宝早教c语言,爸爸用C语言给孩子早教,孩子逐渐崩溃,网友:你别害孩子秃顶...
  3. 121 买股票的最佳时机
  4. 学 Python,你一定要知道这个马爹利
  5. 百度定位SDK 申请密钥步骤
  6. 云侧还是边侧?英码科技在边缘计算突围的“方法论”
  7. 自组织特征映射(SOFM或SOM)网络解决旅行商问题(TSP)
  8. 装黑苹果卡在苹果图标_解决黑苹果启动logo变形过程小记。
  9. 第八届中国香料香精学术研讨会
  10. EWMA之——EWMA指数加权移动平均模型的Java实现