启动一个简单的web 应用

使用社区提供的模板,启动一个简单的web应用,熟悉下各种Docker命令的使用:

  1. # docker run -d -P training/webapp python app.py
  2. Unable to find image 'training/webapp' locally
  3. Pulling repository training/webapp
  4. 31fa814ba25a: Download complete
  5. 511136ea3c5a: Download complete
  6. f10ebce2c0e1: Download complete
  7. 82cdea7ab5b5: Download complete
  8. 5dbd9cb5a02f: Download complete
  9. 74fe38d11401: Download complete
  10. 64523f641a05: Download complete
  11. 0e2afc9aad6e: Download complete
  12. e8fc7643ceb1: Download complete
  13. 733b0e3dbcee: Download complete
  14. a1feb043c441: Download complete
  15. e12923494f6a: Download complete
  16. a15f98c46748: Download complete
  17. Status: Downloaded newer image for training/webapp:latest
  18. d00f94a31e8767271f68ab72eab15a8e805c416b0636877f22a31572d10b718d

-d 启动一个daemon并在后台运行

-P 映射一个网络端口

training/webapp docker社区提供的,预先创建好的模板,里面包含一个简单的Python Flask web应用

  1. # docker ps -l
  2. CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS                     NAMES
  3. d00f94a31e87        training/webapp:latest   "python app.py"     59 seconds ago      Up 56 seconds       0.0.0.0:49153->5000/tcp   hopeful_lalande

-l 查看详细信息

PORTS显示 0.0.0.0:49153->5000/tcp

意思是将Container中的5000端口,映射到host的49153端口。5000是Python Flask 的默认端口。

也可以使用 -p container-port:host-port 命令来指定映射端口号

  1. # docker run -d -p 5000:5000 training/webapp python app.py

查看web应用信息

查看名为hopeful_lalande的docker container中,5000端口的映射信息

  1. # docker port hopeful_lalande 5000
  2. 0.0.0.0:49153

查看web应用日志

  1. # docker logs -f hopeful_lalande
  2. * Running on http://0.0.0.0:5000/
  3. 192.168.254.1 - - [17/Dec/2014 02:30:32] "GET / HTTP/1.1" 200 -
  4. 192.168.254.1 - - [17/Dec/2014 02:30:32] "GET /favicon.ico HTTP/1.1" 404 -
  5. 192.168.254.1 - - [17/Dec/2014 02:30:32] "GET /favicon.ico HTTP/1.1" 404 -

-f 持续查看container日志的标准化输出,类似tail -f

查看进程详细信息

  1. # docker top hopeful_lalande
  2. UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
  3. root                15189               2447                0                   10:24               ?                   00:00:00            python app.py

查看web应用容器详细信息

  1. # docker inspect hopeful_lalande
  2. [{
  3. "AppArmorProfile": "",
  4. "Args": [
  5. "app.py"
  6. ],
  7. "Config": {
  8. "AttachStderr": false,
  9. "AttachStdin": false,
  10. "AttachStdout": false,
  11. "Cmd": [
  12. "python",
  13. "app.py"
  14. ],
  15. "CpuShares": 0,
  16. "Cpuset": "",
  17. "Domainname": "",
  18. "Entrypoint": null,
  19. "Env": [
  20. "HOME=/",
  21. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  22. ],
  23. "ExposedPorts": {
  24. "5000/tcp": {}
  25. },
  26. "Hostname": "d00f94a31e87",
  27. "Image": "training/webapp",
  28. "Memory": 0,
  29. "MemorySwap": 0,
  30. "NetworkDisabled": false,
  31. "OnBuild": null,
  32. "OpenStdin": false,
  33. "PortSpecs": null,
  34. "StdinOnce": false,
  35. "Tty": false,
  36. "User": "",
  37. "Volumes": null,
  38. "WorkingDir": "/opt/webapp"
  39. },
  40. "Created": "2014-12-17T02:24:09.468631143Z",
  41. "Driver": "devicemapper",
  42. "ExecDriver": "native-0.2",
  43. "HostConfig": {
  44. "Binds": null,
  45. "CapAdd": null,
  46. "CapDrop": null,
  47. "ContainerIDFile": "",
  48. "Devices": [],
  49. "Dns": null,
  50. "DnsSearch": null,
  51. "ExtraHosts": null,
  52. "Links": null,
  53. "LxcConf": [],
  54. "NetworkMode": "bridge",
  55. "PortBindings": {},
  56. "Privileged": false,
  57. "PublishAllPorts": true,
  58. "RestartPolicy": {
  59. "MaximumRetryCount": 0,
  60. "Name": ""
  61. },
  62. "SecurityOpt": null,
  63. "VolumesFrom": null
  64. },
  65. "HostnamePath": "/var/lib/docker/containers/d00f94a31e8767271f68ab72eab15a8e805c416b0636877f22a31572d10b718d/hostname",
  66. "HostsPath": "/var/lib/docker/containers/d00f94a31e8767271f68ab72eab15a8e805c416b0636877f22a31572d10b718d/hosts",
  67. "Id": "d00f94a31e8767271f68ab72eab15a8e805c416b0636877f22a31572d10b718d",
  68. "Image": "31fa814ba25ae3426f8710df7a48d567d4022527ef2c14964bb8bc45e653417c",
  69. "MountLabel": "",
  70. "Name": "/hopeful_lalande",
  71. "NetworkSettings": {
  72. "Bridge": "docker0",
  73. "Gateway": "172.17.42.1",
  74. "IPAddress": "172.17.0.8",
  75. "IPPrefixLen": 16,
  76. "MacAddress": "02:42:ac:11:00:08",
  77. "PortMapping": null,
  78. "Ports": {
  79. "5000/tcp": [
  80. {
  81. "HostIp": "0.0.0.0",
  82. "HostPort": "49153"
  83. }
  84. ]
  85. }
  86. },
  87. "Path": "python",
  88. "ProcessLabel": "",
  89. "ResolvConfPath": "/var/lib/docker/containers/d00f94a31e8767271f68ab72eab15a8e805c416b0636877f22a31572d10b718d/resolv.conf",
  90. "State": {
  91. "ExitCode": 0,
  92. "FinishedAt": "0001-01-01T00:00:00Z",
  93. "Paused": false,
  94. "Pid": 15189,
  95. "Restarting": false,
  96. "Running": true,
  97. "StartedAt": "2014-12-17T02:24:11.279426855Z"
  98. },
  99. "Volumes": {},
  100. "VolumesRW": {}
  101. }
  102. ]

输出一个JSON格式的Docker container配置和状态。

也可以通过指定名称,获取某项信息值,如下:

  1. # docker inspect -f '{{ .NetworkSettings.IPAddress }}' hopeful_lalande
  2. 172.17.0.8

停止Web应用

  1. # docker stop hopeful_lalande
  2. hopeful_lalande

停止后,可以使用docker ps -a命令,列出之前所有docker容器

  1. # docker ps -a
  2. CONTAINER ID        IMAGE                    COMMAND                CREATED             STATUS                         PORTS               NAMES
  3. d00f94a31e87        training/webapp:latest   "python app.py"        21 minutes ago      Exited (-1) 43 seconds ago                         hopeful_lalande
  4. 7f22b335fb2c        fedora:latest            "/bin/sh -c 'while t   49 minutes ago      Exited (-1) 40 minutes ago                         silly_archimedes
  5. 。。。

重启Web应用

  1. # docker start hopeful_lalande
  2. hopeful_lalande

删除Web应用

  1. # docker rm hopeful_lalande
  2. Error response from daemon: You cannot remove a running container. Stop the container before attempting removal or use -f
  3. 2014/12/17 10:49:32 Error: failed to remove one or more containers

提示无法删除一个正在运行的container。

停止该container后,重新执行上条命令,成功删除container

在Docker中运行web应用的更多相关文章

  1. 在docker中运行ASP.NET Core Web API应用程序

    本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过程中,也会对docker的使用进行一些简单的描述.对于.NET Cor ...

  2. .NET Core Web 应用部署到 Docker 中运行

    环境介绍 : 虚拟机:VirtualBox 5.1.6 系 统:Ubuntu 16.04.1 LTS 系统准备完成后可以使用 sudo apt-get udpate 和 sudo apt-get up ...

  3. docker中运行ASP.NET Core Web API

    在docker中运行ASP.NET Core Web API应用程序 本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过 ...

  4. 如何让传统ASP.NET网站在Docker中运行

    本文主要描述如何让传统ASP.NET网站在Docker中运行,侧重Docker image 搭建. 使用条件: Docker for windows 用户切换到Windows 容器模式 Windows ...

  5. 在Docker中运行gocd

    gocd是一个持续集成的工具,可视化效果非常好 运行gocd-server 12345 docker run -d --name server -p8153:8153 -p8154:8154 -v / ...

  6. k3d入门指南:在Docker中运行K3s

    在本文中,我们将简单了解k3d,这是一款可让您在安装了Docker的任何地方运行一次性Kubernetes集群的工具,此外在本文中我们还将探讨在使用k3d中可能会出现的一切问题. 什么是k3d? k3 ...

  7. 在Docker中运行torch版的neural style

    相关的代码都在Github上,请参见我的Github,https://github.com/lijingpeng/deep-learning-notes 敬请多多关注哈~~~ 在Docker中运行to ...

  8. ASP.NET Core 网站在Docker中运行

    Docker作为新一代的虚拟化方式,未来肯定会得到广泛的应用,传统虚拟机的部署方式要保证开发环境.测试环境.UAT环境.生产环境的依赖一致性,需要大量的运维人力,使用Docker我们可以实现一次部署, ...

  9. 在Eclipse中运行Web项目Jsp网页时提示端口被占用的解决办法:Several ports (8005, 8888, 8009) required by Tomcat v9.0 Server at localhost are already in use.

    问题: 在Eclipse中运行Web项目Jsp网页启动Tomcat时提示端口被占用: Several ports (8005, 8080, 8009) required by Tomcat v9.0 ...

随机推荐

  1. 使用XmlHelper添加节点C#代码

    接着上一篇:http://keleyi.com/a/bjac/ttssua0f.htm在前篇文章中,给出了C# XML文件操作类XmlHelper的代码,以及使用该类的一个例子,即使用XmlHelpe ...

  2. openlayers方法总结

    openlayers中的一些方法:OpenLayers.Layer::initialize:创建层Div,注册事件:destroy:注销:clone:克隆当前层:setName:设置层name:add ...

  3. SharePoint Error - An unrecognized HTTP response was received when attempting to crawl this item

    SharePoint 2013爬网报错 An unrecognized HTTP response was received when attempting to crawl this item. V ...

  4. SharePoint 2013 REST 服务使用简介

    1.创建测试使用列表”REST Demo”,插入一些测试数据,如下图: 2.添加内容编辑器,并且添加脚本引用以及HTML代码,如下图: Result的Div为显示结果使用,input标签触发REST服 ...

  5. What is research (1)

    This abstract tells me a lot of stories about itself. Here I want to discuss two stories about it. I ...

  6. GpsLocationProvider中的sendExtraCommand方法

    Android系统源码中GpsLocationProvider类中包含sendExtraCommand方法,代码如下 @Override public boolean sendExtraCommand ...

  7. iOS开发init方法解析

    自定义的init方法,都必须调用父类的init方法. 一般情况下为: - (id)init {      [super init];      xxx = xxx; }   通常情况下,这种模式可以满 ...

  8. Masonry(AutoLayout)的使用

    Masonry 仍然在维持. 如果使用 Swift 开发, 建议使用 SnapKit. Masonry 以一种简便可读的代码实现子控件自动布局 ,甚至可以实现一些动画,是一中轻量级的框架. Mason ...

  9. eclipse怎样在线安装hibernate tools插件并使用

    不知不觉,小Alan已经将近3个月没有上班了,最近在复习一些知识,随时准备回到代码世界的战场,今天复习到了Hibernate,记录一下一点点小知识,那就是eclipse下hibernate Tools ...

  10. SVN 使用锁实现独占式签出

      SVN默认并行工作,但是自动合并又做得很渣.团队工作中,如果确实有一些文件希望独占式签出可以使用SVN的特别属性.       Subversion针对此问题的解决方案是提供一种机制,提醒用户在开 ...