docker容器技术系列2:命令大全

前言

前文介绍了docker的基本概念与原理,已经了解了docker的架构(C/S架构),本文将简述docker client的所有命令,并通过一个完整的例子讲述命令的基本用法。

版本信息

[root@t24app1sg ~]<20181106 11:26:43># docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:20:43 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:28:38 2018
  OS/Arch:          linux/amd64
  Experimental:     false

命令大全

说明:不同的版本命令数量可能是不同的,软件是不断迭代开发的嘛。本文简要描述docker 18相关命令,分为management commands和commands。

management commands管理命令

  config      Manage Docker configs     --管理docker的配置
  container   Manage containers         --管理容器
  image       Manage images             --管理镜像
  network     Manage networks           --管理网络
  node        Manage Swarm nodes        --管理集群节点swarm nodes
  plugin      Manage plugins            --管理docker插件
  secret      Manage Docker secrets     --管理docker安全组件(密码之类的)
  service     Manage services           --管理Swarm编排中的服务
  stack       Manage Docker stacks      --管理docker 栈
  swarm       Manage Swarm              --管理集群
  system      Manage Docker             --管理docker(磁盘空间、系统事件event等)
  trust       Manage trust on Docker images --docker镜像中的内容信任
  volume      Manage volumes            --管理磁盘卷

Commands—一般命令:

attach        Attach local standard input, output, and error streams to a running container --分离模式
  build       Build an image from a Dockerfile               --通过dockerfile构建镜像
  commit      Create a new image from a container's changes      --从容器创建新的镜像
  cp          Copy files/folders between a container and the local filesystem  --容器与本地系统间相互拷贝
  create      Create a new container                      --创建一个容器
  diff        Inspect changes to files or directories on a container's filesystem  --检查容器文件系统的差别
  events      Get real time events from the server            --从服务中获取实时事件
  exec        Run a command in a running container                  --在容器中运行命令
  export      Export a container's filesystem as a tar archive               --导出容器的文件系统
  history     Show the history of an image      --显示镜像的历史信息
  images      List images                      --显示所有镜像
  import      Import the contents from a tarball to create a filesystem image    --从tarball导出内容到文件系统镜像
  info        Display system-wide information          --显示docker 系统层信息
  inspect     Return low-level information on Docker objects     --显示docker对象的底层信息
  kill        Kill one or more running containers          --杀死容器
  load        Load an image from a tar archive or STDIN         --载入一个镜像
  login       Log in to a Docker registry      --登入docker仓库
  logout      Log out from a Docker registry    --退出登录仓库
  logs        Fetch the logs of a container        --获取容器的log信息
  pause       Pause all processes within one or more containers     --暂停容器的处理
  port        List port mappings or a specific mapping for the container   --暂停容器的端口映射
  ps          List containers      --查看所有容器
  pull        Pull an image or a repository from a registry     --从仓库中pull一个镜像
  push        Push an image or a repository to a registry      --向仓库推送一个镜像
  rename      Rename a container       --重命名一个容器
  restart     Restart one or more containers      --重启容器
  rm          Remove one or more containers          --删除容器
  rmi         Remove one or more images         --删除镜像
  run         Run a command in a new container     --在新容器中执行命令
  save        Save one or more images to a tar archive (streamed to STDOUT by default)   --保存镜像到tar文件
  search      Search the Docker Hub for images        --到docker hub中搜索镜像
  start       Start one or more stopped containers       --启动停止了的容器
  stats       Display a live stream of container(s) resource usage statistics  --显示容器的资源利用率
  stop        Stop one or more running containers     --停止运行中的容器
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE   --给镜像创建一个tag标签
  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     --更新容器的配置
  version     Show the Docker version information       --显示docker版本信息
  wait     Block until one or more containers stop, then print their exit codes  --阻塞到某个容器停止

一个完整的例子

1. docker images查看所有镜像

[root@t24app1sg docker_pj]<20181106 11:49:28># docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
jboss_t24                                       v1                  3104141b0b0c        19 hours ago        801MB
csdev.registry.cmbchina.cn/public/cmb-rhel7.5   7.5-433             7b875638cfd8        6 weeks ago         201MB

2. docker pull XXX仓库获取一个镜像

[root@t24app1sg docker_pj]<20181106 11:49:41># docker pull csdev.registry.cmbchina.cn/public/cmb-jboss-eap-71:latest
latest: Pulling from public/cmb-jboss-eap-71
378837c0e24a: Pull complete 
e17262bc2341: Pull complete 
0eeb656bc1e6: Pull complete 
77187f02cbef: Pull complete 
72a204610612: Pull complete 
fb9ea86bb958: Pull complete 
Digest: sha256:8d7d7157fd0d672365cd35197a0ec2e169bdaa4279ddd09cb993aeef8a5edbbe
Status: Downloaded newer image for csdev.registry.cmbchina.cn/public/cmb-jboss-eap-71:latest
 [root@t24app1sg docker_pj]<20181106 11:50:55># 

3. 再次docker images查看所有镜像

[root@t24app1sg docker_pj]<20181106 11:50:55># docker images
REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
jboss_t24                                            v1                  3104141b0b0c        19 hours ago        801MB
csdev.registry.cmbchina.cn/public/cmb-rhel7.5        7.5-433             7b875638cfd8        6 weeks ago         201MB
csdev.registry.cmbchina.cn/public/cmb-jboss-eap-71   latest              810ff889c8f7        3 months ago        986MB

4. docker run 在一个新的容器中运行命令

[root@t24app1sg docker_pj]<20181106 12:51:24>#  docker run -ti 810ff889c8f7 /bin/bash
[jboss@5a89f41a3be7 ~]$
说明:-t, --tty               Allocate a pseudo-TTY(分配一个伪终端)
     -i, --interactive       Keep STDIN open even if not attached(交互式保持标准输入open状态)

5. docker ps查看所有容器

 

由此可以发现,我们的容器5a89f41a3be7加载镜像810ff889c8f7启动成功。

总结

         通过上面的例子可以看出,docker的命令通俗易懂,一般人都能看懂。然而,要强调的仅仅掌握docker images/pull/run/ps等命令是远远不够的,后续还有port、volume、swarm、event等高级应用以及其背后的原理(网络、计算、存储和内核命名空间namespace),系列博文将会一一讲述。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值