查看Docker版本号的命令为(查看docker的版本信息)

查看Docker版本号的命令为(查看docker的版本信息)点击上方蓝字 关注我们哦 容器生命周期管理命令 run 创建一个新的容器 nbsp 使用 docker 镜像 nginx latest 以后台模式启动一个容器 并将容器命名为 mynginx nbsp nbsp docker nbsp run nbsp name nbsp mynginx nbsp d amp

大家好,我是讯享网,很高兴认识大家。




讯享网

点击上方蓝字关注我们哦

容器生命周期管理命令

run

创建一个新的容器。

# 使用docker镜像nginx:latest以后台模式启动一个容器,并将容器命名为mynginx。  
docker run –name mynginx -d nginx:latest  

# 使用镜像 nginx:latest,以后台模式启动一个容器,将容器的 80 端口映射到主机的 80 端口,主机的目录 /data 映射到容器的 /data。  
docker run -p 80:80 -v /data:/data -d nginx:latest  

# 使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。  
docker run -it nginx:latest /bin/bash  

讯享网

start/stop/restart

  • docker start : 启动一个或多个已经被停止的容器。
  • docker stop : 停止一个运行中的容器。
  • docker restart : 重启容器。
讯享网# 启动已被停止的容器mynginx  
docker start mynginx  

# 停止运行中的容器mynginx  
docker stop mynginx  

# 重启容器mynginx  
docker restart mynginx  

kill

杀掉一个运行中的容器。可选参数:

  • -s : 发送什么信号到容器,默认 KILL
# 根据容器名字杀掉容器  
docker kill tomcat7  

# 根据容器ID杀掉容器  
docker kill 65d4a94f7a39  

rm

删除一个或多个容器。

讯享网# 强制删除容器 db01、db02:  
docker rm -f db01 db02  

# 删除容器 nginx01, 并删除容器挂载的数据卷:  
docker rm -v nginx01  

# 删除所有已经停止的容器:  
docker&nbsp;rm&nbsp;\((docker&nbsp;ps&nbsp;-a&nbsp;-q)</span>&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>create</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">创建一个新的容器但不启动它。</span></p><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;使用docker镜像nginx:latest创建一个容器,并将容器命名为mynginx&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(178, 148, 187);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">create</span>&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">--name&nbsp;mynginx&nbsp;nginx:latest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>exec</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">在运行的容器中执行命令。可选参数:</span></p><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-d : 分离模式: 在后台运行</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-i : 即使没有附加也保持STDIN 打开</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-t : 分配一个伪终端</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;在容器&nbsp;mynginx&nbsp;中以交互模式执行容器内&nbsp;/root/nginx.sh&nbsp;脚本&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">exec</span>&nbsp;-it&nbsp;mynginx&nbsp;/bin/sh&nbsp;/root/nginx.sh&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;在容器&nbsp;mynginx&nbsp;中开启一个交互模式的终端&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">exec</span>&nbsp;-i&nbsp;-t&nbsp;&nbsp;mynginx&nbsp;/bin/bash&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;也可以通过 docker ps -a 命令查看已经在运行的容器,然后使用容器 ID 进入容器。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;ps&nbsp;-a&nbsp;&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">exec</span>&nbsp;-it&nbsp;9df70f9a0714&nbsp;/bin/bash&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>pause/unpause</strong></span></h4><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">docker pause :暂停容器中所有的进程。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">docker unpause :恢复容器中所有的进程。</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;暂停数据库容器db01提供服务。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(240, 198, 116);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">docker</span>&nbsp;pause&nbsp;db01&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;恢复数据库容器&nbsp;db01&nbsp;提供服务&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;unpause&nbsp;db0&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><section data-role="paragraph"><p style="vertical-align:inherit;"><br /></p></section><section data-tools="135编辑器" data-id="99664"><section style="margin: 10px auto;text-align: center;"><section style="display: inline-block;"><section style="background-color: rgb(11, 121, 255);background-image: url(&quot;https://mmbiz.qpic.cn/mmbiz_jpg/wfCfIwWSzy8LDojc3bScEJKr8OlHnrpjPhZtjRicTRXBGAG611s7KBq6Qia8bwez6SE80j3dapmkrzjlqPIy9RCg/640?wx_fmt=jpeg&quot;);background-repeat: no-repeat;background-position: right bottom;background-size: 100%;padding: 6px 1em;box-sizing: border-box;"><section data-brushtype="text" style="font-size: 16px;letter-spacing: 1.5px;color: #fff;"><strong>容器操作命令</strong></section></section></section></section></section><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>ps</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">列出容器。可选参数:</span></p><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-a : 显示所有的容器,包括未运行的。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-f : 根据条件过滤显示的内容。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–format : 指定返回值的模板文件。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-l : 显示最近创建的容器。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-n : 列出最近创建的n个容器。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–no-trunc : 不截断输出。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-q : 静默模式,只显示容器编号。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-s : 显示总的文件大小。</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;列出所有在运行的容器信息。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(240, 198, 116);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">docker</span>&nbsp;ps&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;列出最近创建的5个容器信息。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;ps&nbsp;-n&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">5</span>&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;列出所有创建的容器ID。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;ps&nbsp;-a&nbsp;-q&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><blockquote style="padding: 15px 15px 15px 1rem;outline: 0px;border-left-width: 6px;border-left-color: rgb(220, 230, 240);color: rgb(129, 145, 152);font-size: 0.9em;max-width: 100%;overflow-wrap: normal;line-height: inherit;background: rgb(242, 247, 251);overflow: auto;word-break: normal;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;"><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;font-size: inherit;color: inherit;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">补充说明:容器的7种状态:created(已创建)、restarting(重启中)、running(运行中)、removing(迁移中)、paused(暂停)、exited(停止)、dead(死亡)。</span></p></blockquote><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>inspect</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">获取容器/镜像的元数据。可选参数:</span></p><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-f : 指定返回值的模板文件。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-s : 显示总的文件大小。</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–type : 为指定类型返回JSON。</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;获取镜像mysql:5.7的元信息。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(240, 198, 116);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">docker</span>&nbsp;inspect&nbsp;mysql:<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">5</span>.<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">7</span>&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;获取正在运行的容器mymysql的 IP。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;inspect&nbsp;--format=<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">'{{range&nbsp;.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'</span>&nbsp;mymysql&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>top</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">查看容器中运行的进程信息,支持 ps 命令参数。</span></p><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;查看容器mymysql的进程信息。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;top&nbsp;mymysql&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;查看所有运行容器的进程信息。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(178, 148, 187);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">for</span>&nbsp;i&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(178, 148, 187);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">in</span>&nbsp;&nbsp;`docker&nbsp;ps&nbsp;|grep&nbsp;Up|awk&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">'{print&nbsp;\)1}’;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(178, 148, 187);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">do</span>&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">echo</span>&nbsp;\&nbsp;&amp;&amp;docker&nbsp;top&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(204, 102, 102);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">$i</span>;&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(178, 148, 187);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">done</span>&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>events</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">获取实时事件。参数说明:</span></p><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-f :根据条件过滤事件;</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–since :从指定的时间戳后显示所有事件;</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–until :流水时间显示到指定的时间为止;</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;显示docker 2016年7月1日后的所有事件。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(240, 198, 116);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">docker</span>&nbsp;events&nbsp;&nbsp;--since=<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">""</span>&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;显示docker 镜像为mysql:5.6 2016年7月1日后的相关事件。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;events&nbsp;-f&nbsp;<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">"image"</span>=<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">"mysql:5.6"</span>&nbsp;--since=<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">""</span>&nbsp;&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><blockquote style="padding: 15px 15px 15px 1rem;outline: 0px;border-left-width: 6px;border-left-color: rgb(220, 230, 240);color: rgb(129, 145, 152);font-size: 0.9em;max-width: 100%;overflow-wrap: normal;line-height: inherit;background: rgb(242, 247, 251);overflow: auto;word-break: normal;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;"><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;font-size: inherit;color: inherit;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">说明:如果指定的时间是到秒级的,需要将时间转成时间戳。如果时间为日期的话,可以直接使用,如–since=“2016-07-01”。</span></p></blockquote><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>logs</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">获取容器的日志。参数说明:</span></p><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-f : 跟踪日志输出</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–since : 显示某个开始时间的所有日志</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-t : 显示时间戳</span></p></li><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">–tail : 仅列出最新N条容器日志</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;跟踪查看容器mynginx的日志输出。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(240, 198, 116);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">docker</span>&nbsp;logs&nbsp;-f&nbsp;mynginx&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(150, 152, 150);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;查看容器mynginx从2016年7月1日后的最新10条日志。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;logs&nbsp;--since=<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(181, 189, 104);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">"2016-07-01"</span>&nbsp;--tail=<span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(222, 147, 95);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">10</span>&nbsp;mynginx&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /></span></p></pre><h4 style="margin: 2px 5px;outline: 0px;font-size: 1.2em;max-width: 100%;color: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong>export</strong></span></h4><p style="text-align:justify;vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;line-height: 2em;font-family: Helvetica, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">将文件系统作为一个tar归档文件导出到STDOUT。参数说明:</span></p><ul class="list-paddingleft-2" style="padding-left: 30px;outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;font-family: Helvetica, Arial, sans-serif;overflow-wrap: break-word !important;"><li><p style="vertical-align: inherit;margin: 2px 5px;outline: 0px;max-width: 100%;line-height: 2em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">-o : 将输入内容写到文件。</span></p></li></ul><pre style="outline: 0px;max-width: 100%;color: inherit;font-size: inherit;background-color: rgb(255, 255, 255);line-height: inherit;box-sizing: border-box !important;overflow-wrap: break-word !important;"><p style="vertical-align: inherit;margin: 2px 5px;padding: 0.5em;outline: 0px;max-width: 100%;font-size: 14px;letter-spacing: 0px;border-radius: 0px;background: rgb(29, 31, 33);color: rgb(197, 200, 198);line-height: 2em;box-sizing: border-box !important;overflow-wrap: normal !important;word-break: normal !important;overflow: auto !important;display: -webkit-box !important;font-family: Consolas, Inconsolata, Courier, monospace;"><span style="font-size: 15px;font-family: Helvetica, Arial, sans-serif;"><span style="outline: 0px;max-width: 100%;line-height: inherit;color: rgb(129, 162, 190);box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">#&nbsp;将id为a404c6c174a2的容器按日期保存为tar文件。&nbsp;&nbsp;</span><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />docker&nbsp;export&nbsp;-o&nbsp;mysql-<span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">date&nbsp;+%Y%m%d</span>.tar&nbsp;a404c6c174a2&nbsp;&nbsp;<br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;" />ls&nbsp;mysql-<span style="outline: 0px;max-width: 100%;color: inherit;line-height: inherit;box-sizing: border-box !important;overflow-wrap: inherit !important;word-break: inherit !important;">date&nbsp;+%Y%m%d`
.tar&nbsp;&nbsp;

port

列出指定的容器的端口映射。

#&nbsp;查看容器mynginx的端口映射情况。&nbsp;&nbsp;
docker&nbsp;port&nbsp;mymysql&nbsp;&nbsp;
容器rootfs

commit

从容器创建一个新的镜像。参数说明:

  • -a : 提交的镜像作者;
  • -c : 使用Dockerfile指令来创建镜像;
  • -m : 提交时的说明文字;
  • -p : 在commit时,将容器暂停。
讯享网#&nbsp;将容器a404c6c174a2 保存为新的镜像,并添加提交人信息和说明信息。&nbsp;&nbsp;
docker&nbsp;commit&nbsp;-a&nbsp;“guodong”&nbsp;-m&nbsp;“my&nbsp;db”&nbsp;a404c6c174a2&nbsp;&nbsp;mymysql:v1&nbsp;&nbsp;&nbsp;

cp

用于容器与主机之间的数据拷贝。参数说明:

  • -L : 保持源目标中的链接
#&nbsp;将主机/www/runoob目录拷贝到容器96f7f14e99ab的/www目录下。&nbsp;&nbsp;
docker&nbsp;cp&nbsp;/www/runoob&nbsp;96f7f14e99ab:/www/&nbsp;&nbsp;

#&nbsp;将主机/www/runoob目录拷贝到容器96f7f14e99ab中,目录重命名为www。&nbsp;&nbsp;
docker&nbsp;cp&nbsp;/www/runoob&nbsp;96f7f14e99ab:/www&nbsp;&nbsp;

#&nbsp;将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。&nbsp;&nbsp;
docker&nbsp;cp&nbsp;&nbsp;96f7f14e99ab:/www&nbsp;/tmp/&nbsp;&nbsp;

diff

检查容器里文件结构的更改。

讯享网#&nbsp;查看容器mymysql的文件结构更改。&nbsp;&nbsp;
docker&nbsp;diff&nbsp;mymysql&nbsp;&nbsp;
镜像仓库命令

login/logout

docker login : 登陆到一个Docker镜像仓库,如果未指定镜像仓库地址,默认为官方仓库 Docker Hubdocker logout : 登出一个Docker镜像仓库,如果未指定镜像仓库地址,默认为官方仓库 Docker Hub参数说明:

  • -u : 登陆的用户名
  • -p : 登陆的密码
#&nbsp;登陆到Docker&nbsp;Hub&nbsp;&nbsp;
docker&nbsp;login&nbsp;-u&nbsp;用户名&nbsp;-p&nbsp;密码&nbsp;&nbsp;

#&nbsp;登出Docker&nbsp;Hub&nbsp;&nbsp;
docker&nbsp;logout&nbsp;&nbsp;

pull

从镜像仓库中拉取或者更新指定镜像。参数说明:

  • -a : 拉取所有 tagged 镜像
  • –disable-content-trust : 忽略镜像的校验,默认开启
讯享网#&nbsp;从Docker Hub下载java最新版镜像。&nbsp;&nbsp;
docker&nbsp;pull&nbsp;java&nbsp;&nbsp;

#&nbsp;从Docker Hub下载REPOSITORY为java的所有镜像。&nbsp;&nbsp;
docker&nbsp;pull&nbsp;-a&nbsp;java&nbsp;&nbsp;

push

将本地的镜像上传到镜像仓库,要先登陆到镜像仓库。参数说明:

  • –disable-content-trust : 忽略镜像的校验,默认开启
#&nbsp;上传本地镜像myapache:v1到镜像仓库中。&nbsp;&nbsp;
docker&nbsp;push&nbsp;myapache:v1&nbsp;&nbsp;

search

从Docker Hub查找镜像。参数说明:

  • –automated : 只列出 automated build类型的镜像;
  • –no-trunc : 显示完整的镜像描述;
  • -f &lt;过滤条件&gt;: 列出指定条件的镜像。
讯享网#&nbsp;从&nbsp;Docker&nbsp;Hub&nbsp;查找所有镜像名包含&nbsp;java,并且收藏数大于&nbsp;10&nbsp;的镜像&nbsp;&nbsp;
docker&nbsp;search&nbsp;-f&nbsp;stars=10&nbsp;java&nbsp;&nbsp;

NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DESCRIPTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STARS&nbsp;&nbsp;&nbsp;OFFICIAL&nbsp;&nbsp;&nbsp;AUTOMATED&nbsp;&nbsp;
java&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Java&nbsp;is&nbsp;a&nbsp;concurrent,&nbsp;class-based…&nbsp;&nbsp;&nbsp;1037&nbsp;&nbsp;&nbsp;&nbsp;[OK]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
anapsix/alpine-java&nbsp;&nbsp;&nbsp;Oracle&nbsp;Java&nbsp;8&nbsp;(and&nbsp;7)&nbsp;with&nbsp;GLIBC&nbsp;…&nbsp;&nbsp;&nbsp;115&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[OK]&nbsp;&nbsp;
develar/java&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;46&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[OK]&nbsp;&nbsp;

每列参数说明:

  • NAME: 镜像仓库源的名称
  • DESCRIPTION: 镜像的描述
  • OFFICIAL: 是否 docker 官方发布
  • stars: 类似 Github 里面的 star,表示点赞、喜欢的意思
  • AUTOMATED: 自动构建
本地镜像管理命令

images

列出本地镜像。参数说明:

  • -a : 列出本地所有的镜像(含中间映像层,默认情况下,过滤掉中间映像层);
  • –digests : 显示镜像的摘要信息;
  • -f : 显示满足条件的镜像;
  • –format : 指定返回值的模板文件;
  • –no-trunc : 显示完整的镜像信息;
  • -q : 只显示镜像ID。

#&nbsp;查看本地镜像列表。&nbsp;&nbsp;
docker&nbsp;images&nbsp;&nbsp;

#&nbsp;列出本地镜像中REPOSITORY为ubuntu的镜像列表。&nbsp;&nbsp;
docker&nbsp;images&nbsp;&nbsp;ubuntu&nbsp;&nbsp;

rmi

删除本地一个或多个镜像。参数说明:

  • -f : 强制删除;
  • –no-prune : 不移除该镜像的过程镜像,默认移除;
讯享网#&nbsp;强制删除本地镜像 guodong/ubuntu:v4。&nbsp;&nbsp;
docker&nbsp;rmi&nbsp;-f&nbsp;guodong/ubuntu:v4&nbsp;&nbsp;

tag

标记本地镜像,将其归入某一仓库。

#&nbsp;将镜像ubuntu:15.10标记为 runoob/ubuntu:v3 镜像。&nbsp;&nbsp;
docker&nbsp;tag&nbsp;ubuntu:15.10&nbsp;runoob/ubuntu:v3&nbsp;&nbsp;

build

用于使用 Dockerfile 创建镜像。参数说明:

  • –build-arg=[] : 设置镜像创建时的变量;
  • –cpu-shares : 设置 cpu 使用权重;
  • –cpu-period : 限制 CPU CFS周期;
  • –cpu-quota : 限制 CPU CFS配额;
  • –cpuset-cpus : 指定使用的CPU id;
  • –cpuset-mems : 指定使用的内存 id;
  • –disable-content-trust : 忽略校验,默认开启;
  • -f : 指定要使用的Dockerfile路径;
  • –force-rm : 设置镜像过程中删除中间容器;
  • –isolation : 使用容器隔离技术;
  • –label=[] : 设置镜像使用的元数据;
  • -m : 设置内存最大值;
  • –memory-swap : 设置Swap的最大值为内存+swap,”-1”表示不限swap;
  • –no-cache : 创建镜像的过程不使用缓存;
  • –pull : 尝试去更新镜像的新版本;
  • –quiet, -q : 安静模式,成功后只输出镜像 ID;
  • –rm : 设置镜像成功后删除中间容器;
  • –shm-size : 设置/dev/shm的大小,默认值是64M;
  • –ulimit : Ulimit配置。
  • –squash : 将 Dockerfile 中所有的操作压缩为一层。
  • –tag, -t: 镜像的名字及标签,通常 name:tag 或者 name 格式;可以在一次构建中为一个镜像设置多个标签。
  • –network: 默认 default。在构建期间设置RUN指令的网络模式
讯享网#&nbsp;使用当前目录的&nbsp;Dockerfile&nbsp;创建镜像,标签为&nbsp;runoob/ubuntu:v1&nbsp;&nbsp;
docker&nbsp;build&nbsp;-t&nbsp;runoob/ubuntu:v1&nbsp;.&nbsp;&nbsp;&nbsp;

#&nbsp;使用URL&nbsp;github.com/creack/docker-firefox&nbsp;的&nbsp;Dockerfile&nbsp;创建镜像&nbsp;&nbsp;
docker&nbsp;build&nbsp;github.com/creack/docker-firefox&nbsp;&nbsp;

#&nbsp;通过&nbsp;-f&nbsp;Dockerfile文件的位置&nbsp;创建镜像&nbsp;&nbsp;
docker&nbsp;build&nbsp;-f&nbsp;/path/to/a/Dockerfile&nbsp;.&nbsp;&nbsp;

history

查看指定镜像的创建历史。参数说明:

  • -H : 以可读的格式打印镜像大小和日期,默认为true;
  • –no-trunc : 显示完整的提交记录;
  • -q : 仅列出提交记录ID。
#&nbsp;查看本地镜像 guodong/ubuntu:v3 的创建历史。&nbsp;&nbsp;
docker&nbsp;history&nbsp;guodong/ubuntu:v3&nbsp;&nbsp;

save

将指定镜像保存成 tar 归档文件。参数说明:

  • -o : 输出到的文件。
讯享网#&nbsp;将镜像&nbsp;runoob/ubuntu:v3&nbsp;生成&nbsp;my_ubuntu_v3.tar&nbsp;文档&nbsp;&nbsp;
docker&nbsp;save&nbsp;-o&nbsp;my_ubuntu_v3.tar&nbsp;runoob/ubuntu:v3&nbsp;&nbsp;

load

导入使用 docker save 命令导出的镜像。参数说明:

  • –input , -i : 指定导入的文件,代替 STDIN。
  • –quiet , -q : 精简输出信息。
#&nbsp;导入镜像&nbsp;&nbsp;
docker&nbsp;load&nbsp;–input&nbsp;fedora.tar&nbsp;&nbsp;

import

从归档文件中创建镜像。参数说明:

  • -c : 应用docker 指令创建镜像;
  • -m : 提交时的说明文字;
讯享网#&nbsp;从镜像归档文件my_ubuntu_v3.tar创建镜像,命名为runoob/ubuntu:v4&nbsp;&nbsp;
docker&nbsp;import&nbsp;&nbsp;my_ubuntu_v3.tar&nbsp;runoob/ubuntu:v4&nbsp;&nbsp;&nbsp;&nbsp;
基础版本信息命令

info

显示 Docker 系统信息,包括镜像和容器数。

#&nbsp;查看docker系统信息。&nbsp;&nbsp;
docker&nbsp;info&nbsp;&nbsp;

version

显示 Docker 版本信息。

讯享网docker&nbsp;version&nbsp;&nbsp;

扫码关注我们

小讯
上一篇 2025-06-06 15:56
下一篇 2025-05-23 15:17

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/139130.html