1.启动docker

  1. sudo systemctl start docker
  2. sudo systemctl restart docker
  3. sudo systemctl stop docker
  4. sudo systemctl status docker
2.查看docker信息
  1. sudo docker info
  1. Containers: 1
  2. Running: 0
  3. Paused: 0
  4. Stopped: 1
  5. Images: 2
  6. Server Version: 17.03.1-ce
  7. Storage Driver: devicemapper
  8. Pool Name: vgdocker-thinpool
  9. Pool Blocksize: 524.3 kB
  10. Base Device Size: 10.74 GB
  11. Backing Filesystem: xfs
  12. Data file:
  13. Metadata file:
  14. Data Space Used: 2.708 GB
  15. Data Space Total: 20.4 GB
  16. Data Space Available: 17.69 GB
  17. Metadata Space Used: 1.917 MB
  18. Metadata Space Total: 213.9 MB
  19. Metadata Space Available: 212 MB
  20. Thin Pool Minimum Free Space: 2.039 GB
  21. Udev Sync Supported: true
  22. Deferred Removal Enabled: true
  23. Deferred Deletion Enabled: true
  24. Deferred Deleted Device Count: 0
  25. Library Version: 1.02.135-RHEL7 (2016-11-16)
  26. Logging Driver: json-file
  27. Cgroup Driver: cgroupfs
  28. Plugins:
  29. Volume: local
  30. Network: bridge host macvlan null overlay
  31. Swarm: inactive
  32. Runtimes: runc
  33. Default Runtime: runc
  34. Init Binary: docker-init
  35. containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
  36. runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
  37. init version: 949e6fa
  38. Security Options:
  39. seccomp
  40. Profile: default
  41. Kernel Version: 3.10.0-123.el7.x86_64
  42. Operating System: CentOS Linux 7 (Core)
  43. OSType: linux
  44. Architecture: x86_64
  45. CPUs: 2
  46. Total Memory: 3.69 GiB
  47. Name: wgl
  48. ID: 2GXU:7CL7:ETAC:BTYX:M4V6:JSMV:3CIJ:4OZC:KKKX:D5IV:DVBX:T3KV
  49. Docker Root Dir: /var/lib/docker
  50. Debug Mode (client): false
  51. Debug Mode (server): false
  52. Registry: https://index.docker.io/v1/
  53. WARNING: bridge-nf-call-iptables is disabled
  54. WARNING: bridge-nf-call-ip6tables is disabled
  55. Experimental: false
  56. Insecure Registries:
  57. 127.0.0.0/8
  58. Live Restore Enabled: false
3.运行第一个容器
  1. sudo docker run --name wgl_centos -i -t centos /bin/bash
  2. sudo docker rename oldername newname
 
      -i  保证容器中stdin是开启的,尽管我们并没有附着到容器中,是交互式shell的半边天;-t  是另一半边天,他告诉docker为要创建的容器分配一个伪tty终端。如要在命令行下创建一个我们能与之经行交互的容器,而不是一个运行后台服务的容器,这两个是基本的了。

4.查看宿主机容器列表
  1. sudo docker ps -a #显示全部容器
  2. sudo docker ps -l #列出最后一个运行的容器,也可以--format进一步控制显示
  3. sudo docker ps -n x #显示最后x个容器。
5.启动,停止容器
  1. sudo docker start(restart,stop) 容器ID(容器name)
6,附着到容器上
  1. sudo docker attach 容器
例如
sudo docker start dreamy_knuth    先启动(启动后会沿用run命令时指定的参数运行)
sudo docker attach dreamy_knuth 后附着到容器,【及进入交互界面】
相当于
sudo docker start dreamy_knuth 
sudo docker exec -i -t dreamy_knuth  /bin.bash(可用于打开一个守护式容器)
 
7,创建守护式容器
  1. sudo docker run --name wgl_centos_daemon -d centos /bin/sh -c "while true;do echo hello world;sleep 3;done"
在后台运行,只返回容器ID。
-d 在后台运行
 
8.获取守护式容器的日志
  1. sudo docker logs 容器 #输出最后几条后返回
  2. sudo docker logs -f 容器 #监控日志
  3. sudo docker logs --tail 10 容器 #获取容器日志最后10条
  4. sudo docker logs --tail 0 -f 容器 #跟踪最新日志
  5. sudo docker logs -ft 容器 #监控日志+时间戳
 
9.dockers日志驱动
  1. sudo docker run --log-driver="syslog" --name wgl_centos_daemon -d centos /bin/sh -c "while true;do echo hello world;sleep 3;done"
--log-driver=
syslog 将容器日志重新定向到Syslog,禁用dockers logs命令
json-file 默认,用dockers logs命令查看
none 禁用所有容器中的日志,禁用dockers logs命令
 
10.查看容器进程
  1. sudo docker top wgl_centos_daemon
11.docker统计信息
  1. sudo docker stats [容器1 容器2 容器3 ...]

 
12.在容器内部运行进程
 
后台式任务与交互式任务
 
后台式任务
  1. sudo docker exec -d 53fc4852ce08 touch /opt/wgl.log # -u 为新启动的进程指定属主
通过docker exec 后台命令,可维护,监控,管理正在运行的容器
 
进入容器(不论是守护式还是交互式)的交互式界面
  1. sudo docker exec -it 53fc4852ce08 /bin/bash
 
13,自动重启容器
  1. sudo docker run --restart=always --name wgl_centos_daemon -d centos /bin/sh -c "while true;do echo hello world;sleep 3;done"
--restart会检查日期的退出代码
always        不认退出代码是什么,都重启
on-failure    退出代码非0才重启,还可以设置重启次数:--restart=on-failure:5
 
14.深入容器,容器详情
  1. sudo docker inspect 容器
 
  1. [dwsoft@wgl ~]$ sudo docker inspect wgl_centos_daemon
  2. [
  3. {
  4. "Id": "53fc4852ce081422068efa8bdcbad05d8b51b4fe2ba0a4389c91508dc3fbd50a",
  5. "Created": "2017-05-28T05:35:00.155823247Z",
  6. "Path": "/bin/sh",
  7. "Args": [
  8. "-c",
  9. "while true;do echo hello world;sleep 3;done"
  10. ],
  11. "State": {
  12. "Status": "running",
  13. "Running": true,
  14. "Paused": false,
  15. "Restarting": false,
  16. "OOMKilled": false,
  17. "Dead": false,
  18. "Pid": 6450,
  19. "ExitCode": 0,
  20. "Error": "",
  21. "StartedAt": "2017-05-28T05:35:01.363485741Z",
  22. "FinishedAt": "0001-01-01T00:00:00Z"
  23. },
  24. "Image": "sha256:8140d0c64310d4e290bf3938757837dbb8f806acba0cb3f6a852558074345348",
  25. "ResolvConfPath": "/var/lib/docker/containers/53fc4852ce081422068efa8bdcbad05d8b51b4fe2ba0a4389c91508dc3fbd50a/resolv.conf",
  26. "HostnamePath": "/var/lib/docker/containers/53fc4852ce081422068efa8bdcbad05d8b51b4fe2ba0a4389c91508dc3fbd50a/hostname",
  27. "HostsPath": "/var/lib/docker/containers/53fc4852ce081422068efa8bdcbad05d8b51b4fe2ba0a4389c91508dc3fbd50a/hosts",
  28. "LogPath": "/var/lib/docker/containers/53fc4852ce081422068efa8bdcbad05d8b51b4fe2ba0a4389c91508dc3fbd50a/53fc4852ce081422068efa8bdcbad05d8b51b4fe2ba0a
  29. 4389c91508dc3fbd50a-json.log", "Name": "/wgl_centos_daemon",
  30. "RestartCount": 0,
  31. "Driver": "devicemapper",
  32. "MountLabel": "",
  33. "ProcessLabel": "",
  34. "AppArmorProfile": "",
  35. "ExecIDs": null,
  36. "HostConfig": {
  37. "Binds": null,
  38. "ContainerIDFile": "",
  39. "LogConfig": {
  40. "Type": "json-file",
  41. "Config": {}
  42. },
  43. "NetworkMode": "default",
  44. "PortBindings": {},
  45. "RestartPolicy": {
  46. "Name": "no",
  47. "MaximumRetryCount": 0
  48. },
  49. "AutoRemove": false,
  50. "VolumeDriver": "",
  51. "VolumesFrom": null,
  52. "CapAdd": null,
  53. "CapDrop": null,
  54. "Dns": [],
  55. "DnsOptions": [],
  56. "DnsSearch": [],
  57. "ExtraHosts": null,
  58. "GroupAdd": null,
  59. "IpcMode": "",
  60. "Cgroup": "",
  61. "Links": null,
  62. "OomScoreAdj": 0,
  63. "PidMode": "",
  64. "Privileged": false,
  65. "PublishAllPorts": false,
  66. "ReadonlyRootfs": false,
  67. "SecurityOpt": null,
  68. "UTSMode": "",
  69. "UsernsMode": "",
  70. "ShmSize": 67108864,
  71. "Runtime": "runc",
  72. "ConsoleSize": [
  73. 0,
  74. 0
  75. ],
  76. "Isolation": "",
  77. "CpuShares": 0,
  78. "Memory": 0,
  79. "NanoCpus": 0,
  80. "CgroupParent": "",
  81. "BlkioWeight": 0,
  82. "BlkioWeightDevice": null,
  83. "BlkioDeviceReadBps": null,
  84. "BlkioDeviceWriteBps": null,
  85. "BlkioDeviceReadIOps": null,
  86. "BlkioDeviceWriteIOps": null,
  87. "CpuPeriod": 0,
  88. "CpuQuota": 0,
  89. "CpuRealtimePeriod": 0,
  90. "CpuRealtimeRuntime": 0,
  91. "CpusetCpus": "",
  92. "CpusetMems": "",
  93. "Devices": [],
  94. "DiskQuota": 0,
  95. "KernelMemory": 0,
  96. "MemoryReservation": 0,
  97. "MemorySwap": 0,
  98. "MemorySwappiness": -1,
  99. "OomKillDisable": false,
  100. "PidsLimit": 0,
  101. "Ulimits": null,
  102. "CpuCount": 0,
  103. "CpuPercent": 0,
  104. "IOMaximumIOps": 0,
  105. "IOMaximumBandwidth": 0
  106. },
  107. "GraphDriver": {
  108. "Name": "devicemapper",
  109. "Data": {
  110. "DeviceId": "76",
  111. "DeviceName": "docker-253:1-277138-721bd5780ec0a2800c9db53413e77636e96e787a4b330b9d665c2cf289c01c43",
  112. "DeviceSize": "10737418240"
  113. }
  114. },
  115. "Mounts": [],
  116. "Config": {
  117. "Hostname": "53fc4852ce08",
  118. "Domainname": "",
  119. "User": "",
  120. "AttachStdin": false,
  121. "AttachStdout": false,
  122. "AttachStderr": false,
  123. "Tty": false,
  124. "OpenStdin": false,
  125. "StdinOnce": false,
  126. "Env": [
  127. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  128. ],
  129. "Cmd": [
  130. "/bin/sh",
  131. "-c",
  132. "while true;do echo hello world;sleep 3;done"
  133. ],
  134. "Image": "centos",
  135. "Volumes": null,
  136. "WorkingDir": "",
  137. "Entrypoint": null,
  138. "OnBuild": null,
  139. "Labels": {
  140. "build-date": "20170510",
  141. "license": "GPLv2",
  142. "name": "CentOS Base Image",
  143. "vendor": "CentOS"
  144. }
  145. },
  146. "NetworkSettings": {
  147. "Bridge": "",
  148. "SandboxID": "dc56c0446f06b8b53b914574c34ec35c09fa38bc9d43d70ba5750aef60915597",
  149. "HairpinMode": false,
  150. "LinkLocalIPv6Address": "",
  151. "LinkLocalIPv6PrefixLen": 0,
  152. "Ports": {},
  153. "SandboxKey": "/var/run/docker/netns/dc56c0446f06",
  154. "SecondaryIPAddresses": null,
  155. "SecondaryIPv6Addresses": null,
  156. "EndpointID": "0da7299f69c100fce911e1c6b12f333e56ff30e3ff7a2f799ee595af89265fc8",
  157. "Gateway": "172.17.0.1",
  158. "GlobalIPv6Address": "",
  159. "GlobalIPv6PrefixLen": 0,
  160. "IPAddress": "172.17.0.2",
  161. "IPPrefixLen": 16,
  162. "IPv6Gateway": "",
  163. "MacAddress": "02:42:ac:11:00:02",
  164. "Networks": {
  165. "bridge": {
  166. "IPAMConfig": null,
  167. "Links": null,
  168. "Aliases": null,
  169. "NetworkID": "23e919387bcf6493c7bdcd91e31b8995132fb7f081cfbac7778e855c6a4f6d58",
  170. "EndpointID": "0da7299f69c100fce911e1c6b12f333e56ff30e3ff7a2f799ee595af89265fc8",
  171. "Gateway": "172.17.0.1",
  172. "IPAddress": "172.17.0.2",
  173. "IPPrefixLen": 16,
  174. "IPv6Gateway": "",
  175. "GlobalIPv6Address": "",
  176. "GlobalIPv6PrefixLen": 0,
  177. "MacAddress": "02:42:ac:11:00:02"
  178. }
  179. }
  180. }
  181. }
  182. ]
 
也可用-f或--format,查看选定的结果,可查看多个容器,多个结果。

 
 
15,删除容器
  1. sudo docker rm 容器
  2. sudo docker rm -f 容器 #删除正在运行的容器
  3. sudo docker rm `sudo docker ps -a -q` # -q只返回容器ID
 
 

docker基础及命令的更多相关文章

  1. docker基础维护命令

    docker images显示当前存在的images docker ps,显示当前的container docker rm containerId 删除指定的container(需要先停止,才能删除) ...

  2. Docker - Docker基础命令及使用

    Docker Docker - 官网 Docker - Hub GitHub - Docker Docker中文社区 Docker基础命令 Docker 查看帮助信息:docker --help 查看 ...

  3. 1. Docker基础命令

    本文简要介绍Docker的基础命令,目的在于快速入门Dokcer,Docker的完整命令可以参考Docker官方手册. 0. 安装Docker Docker当前分为企业版(Docker Enterpr ...

  4. Docker基础修炼2--Docker镜像原理及常用命令

    通过前文的讲解对Docker有了基本认识之后,我们开始进入实战操作,本文先演示Docker三要素之镜像原理和相关命令. 本文的演示环境仍然沿用上一篇文章在本地Centos7中安装的环境,如果你本地没有 ...

  5. docker基础命令和操作

    前言 之前在部署个人网站的时候,需要打包maven,在生产环境,需要使用到docker去做服务器和端口的守护. 于是在查阅了相关资料,学习了docker一些基本命令行操作,包括对镜像的查看,修改和添加 ...

  6. docker基础命令,常用操作

    docker基础命令 使用docker镜像 获取镜像 从docker registry获取镜像的命令是docker pull.命令格式是: docker pull [选项][docker regist ...

  7. Docker基础和常用命令

    Docker基础和常用命令 一,Docker 简介 1.1,什么是 Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,nam ...

  8. Docker 基础命令 简要入门

    本文出自:http://www.cnblogs.com/scoter2008,本文将持续更新所有docker都可以通过man查看帮助:man docker [ps|top|run|...]1.列出正在 ...

  9. docker基础命令详解

    Commands: attach    Attach to a running container build     Build an image from a Dockerfile commit  ...

随机推荐

  1. JMM中的Happens-Before原则

      在java内存模型中,happens-before应该理解为:前一个操作的结果,可以被后续的操作获取,即内存可见性.   为了解决多线程的内存可见性问题,就提出了happens-before原则, ...

  2. linux-head、tail、sort、uniq、pstree、ps

    1.head 默认查看文件前10行 head -7 /etc/yum.conf -n num -n7代表查看文件前7行 2.tail 默认查看文件的后10行 tail -7 /etc/yum.conf ...

  3. vs2015编译zlib静态库步骤

    ZLIB静态库的编译 下载ZLIB源码 ZLib官网下载或者GitHub上直接 clone 下来即可 www.zlib.net 截至目前最新版本1.2.1.1本 如下图我选择从官网下载 下载完以后解压 ...

  4. html页脚固定在底部的方法

    <style type="text/css"> html { height: 100%; } body { height: 100%; margin: 0; paddi ...

  5. WIN10高清壁纸

    下面给大家分享我自己收集的WIN10的壁纸(大家可以存在在自己网盘里) 百度网盘下载 提取码:dsf5

  6. Asp.Net Core下的开源任务调度平台ScheduleMaster

    从何说起 2017年初的时候,由于当时项目需要做了一个乞丐版定时调度系统,那时候只在单机上实现了核心的调度功能.做这个玩意之前也调研了社区中开源的解决方案,找了几个实地部署试跑了一下,其实都很不错.但 ...

  7. MapGIS文件如何压缩存盘

    经过多次编辑修改的MapGIS数据,含有大量逻辑上已删除的节点或图元,数据冗余复杂, 在转换过程前应注意一定要采用压缩存盘方式处理,目的是确保编辑状态已删除的数据真正从物理存储层删除,以确保数据的精简 ...

  8. acmPush模块示例demo

    感谢论坛版主 马浩川 的分享. 模块介绍:  阿里移动推送(Alibaba Cloud Mobile Push)是基于大数据的移动智能推送服务,帮助App快速集成移动推送的功能,在实现高效.精确.实时 ...

  9. springcloud之断路器(Hystrix)

    在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用.为了保证其高可用,单个服务 ...

  10. 安装dbeaver,The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    在连接mysql时,出现了以下错误: 解决方法是 在数据库链接指定useUnicode=true&useSSL=false&characterEncoding=utf8&ser ...