Docker部署Nginx应用(2)

1、拉取Nginx镜像

  1. [root@localhost ~]# docker pull nginx
  2. Using default tag: latest
  3. latest: Pulling from library/nginx
  4. f7e2b70d04ae: Pull complete
  5. 08dd01e3f3ac: Pull complete
  6. d9ef3a1eb792: Pull complete
  7. Digest: sha256:98efe605f61725fd817ea69521b0eeb32bef007af0e3d0aeb6258c6e6fe7fc1a
  8. Status: Downloaded newer image for nginx:latest

2、查看拉取到的镜像

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest 881bd08c0b08 days ago 109MB

3、在Docker中启用Nginx

  1. [root@localhost ~]# docker run -p : --name myNginx -d nginx
  2. ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5

4、查看启动的nginx进程

  1. [root@localhost ~]# ps -ef|grep nginx
  2. root : ? :: nginx: master process nginx -g daemon off;
  3. : ? :: nginx: worker process
  4. root : pts/ :: grep --color=auto nginx

5、访问nginx

  1. [root@localhost ~]# curl http://localhost:80/
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>Welcome to nginx!</title>
  6. <style>
  7. body {
  8. width: 35em;
  9. margin: auto;
  10. font-family: Tahoma, Verdana, Arial, sans-serif;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <h1>Welcome to nginx!</h1>
  16. <p>If you see this page, the nginx web server is successfully installed and
  17. working. Further configuration is required.</p>
  18.  
  19. <p>For online documentation and support please refer to
  20. <a href="http://nginx.org/">nginx.org</a>.<br/>
  21. Commercial support is available at
  22. <a href="http://nginx.com/">nginx.com</a>.</p>
  23.  
  24. <p><em>Thank you for using nginx.</em></p>
  25. </body>
  26. </html>

6、监测Nginx引用状态

  1. [root@localhost ~]# docker inspect ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5
  2. [
  3. {
  4. "Id": "ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5",
  5. "Created": "2019-03-12T09:58:06.595522099Z",
  6. "Path": "nginx",
  7. "Args": [
  8. "-g",
  9. "daemon off;"
  10. ],
  11. "State": {
  12. "Status": "running",
  13. "Running": true,
  14. "Paused": false,
  15. "Restarting": false,
  16. "OOMKilled": false,
  17. "Dead": false,
  18. "Pid": ,
  19. "ExitCode": ,
  20. "Error": "",
  21. "StartedAt": "2019-03-12T09:58:07.12571162Z",
  22. "FinishedAt": "0001-01-01T00:00:00Z"
  23. },
  24. "Image": "sha256:881bd08c0b08234bd19136957f15e4301097f4646c1e700f7fea26e41fc40069",
  25. "ResolvConfPath": "/var/lib/docker/containers/ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5/resolv.conf",
  26. "HostnamePath": "/var/lib/docker/containers/ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5/hostname",
  27. "HostsPath": "/var/lib/docker/containers/ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5/hosts",
  28. "LogPath": "/var/lib/docker/containers/ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5/ad7cc45c81ffadbd44254c1c043e048c677a4ebcd4ca618efcd098729cec2fa5-json.log",
  29. "Name": "/myNginx",
  30. "RestartCount": ,
  31. "Driver": "overlay2",
  32. "Platform": "linux",
  33. "MountLabel": "",
  34. "ProcessLabel": "",
  35. "AppArmorProfile": "",
  36. "ExecIDs": null,
  37. "HostConfig": {
  38. "Binds": null,
  39. "ContainerIDFile": "",
  40. "LogConfig": {
  41. "Type": "json-file",
  42. "Config": {}
  43. },
  44. "NetworkMode": "default",
  45. "PortBindings": {
  46. "80/tcp": [
  47. {
  48. "HostIp": "",
  49. "HostPort": ""
  50. }
  51. ]
  52. },
  53. "RestartPolicy": {
  54. "Name": "no",
  55. "MaximumRetryCount":
  56. },
  57. "AutoRemove": false,
  58. "VolumeDriver": "",
  59. "VolumesFrom": null,
  60. "CapAdd": null,
  61. "CapDrop": null,
  62. "Dns": [],
  63. "DnsOptions": [],
  64. "DnsSearch": [],
  65. "ExtraHosts": null,
  66. "GroupAdd": null,
  67. "IpcMode": "shareable",
  68. "Cgroup": "",
  69. "Links": null,
  70. "OomScoreAdj": ,
  71. "PidMode": "",
  72. "Privileged": false,
  73. "PublishAllPorts": false,
  74. "ReadonlyRootfs": false,
  75. "SecurityOpt": null,
  76. "UTSMode": "",
  77. "UsernsMode": "",
  78. "ShmSize": ,
  79. "Runtime": "runc",
  80. "ConsoleSize": [
  81. ,
  82.  
  83. ],
  84. "Isolation": "",
  85. "CpuShares": ,
  86. "Memory": ,
  87. "NanoCpus": ,
  88. "CgroupParent": "",
  89. "BlkioWeight": ,
  90. "BlkioWeightDevice": [],
  91. "BlkioDeviceReadBps": null,
  92. "BlkioDeviceWriteBps": null,
  93. "BlkioDeviceReadIOps": null,
  94. "BlkioDeviceWriteIOps": null,
  95. "CpuPeriod": ,
  96. "CpuQuota": ,
  97. "CpuRealtimePeriod": ,
  98. "CpuRealtimeRuntime": ,
  99. "CpusetCpus": "",
  100. "CpusetMems": "",
  101. "Devices": [],
  102. "DeviceCgroupRules": null,
  103. "DiskQuota": ,
  104. "KernelMemory": ,
  105. "MemoryReservation": ,
  106. "MemorySwap": ,
  107. "MemorySwappiness": null,
  108. "OomKillDisable": false,
  109. "PidsLimit": ,
  110. "Ulimits": null,
  111. "CpuCount": ,
  112. "CpuPercent": ,
  113. "IOMaximumIOps": ,
  114. "IOMaximumBandwidth": ,
  115. "MaskedPaths": [
  116. "/proc/asound",
  117. "/proc/acpi",
  118. "/proc/kcore",
  119. "/proc/keys",
  120. "/proc/latency_stats",
  121. "/proc/timer_list",
  122. "/proc/timer_stats",
  123. "/proc/sched_debug",
  124. "/proc/scsi",
  125. "/sys/firmware"
  126. ],
  127. "ReadonlyPaths": [
  128. "/proc/bus",
  129. "/proc/fs",
  130. "/proc/irq",
  131. "/proc/sys",
  132. "/proc/sysrq-trigger"
  133. ]
  134. },
  135. "GraphDriver": {
  136. "Data": {
  137. "LowerDir": "/var/lib/docker/overlay2/bc9ef8c119903b79ec581081d835c447ce00b72eb70b07b45d14b3dde7a37c51-init/diff:/var/lib/docker/overlay2/2f3362aabe1d926214bed5c53a425fde596d23861cc6a59168c594974623876a/diff:/var/lib/docker/overlay2/56da5031c7fb61e617765323e953cd71e07679f202f56df818342500f409b50b/diff:/var/lib/docker/overlay2/1321013bc28d4931f52ab6cc47de24b57c6221686aa25c1acea18c7f87131070/diff",
  138. "MergedDir": "/var/lib/docker/overlay2/bc9ef8c119903b79ec581081d835c447ce00b72eb70b07b45d14b3dde7a37c51/merged",
  139. "UpperDir": "/var/lib/docker/overlay2/bc9ef8c119903b79ec581081d835c447ce00b72eb70b07b45d14b3dde7a37c51/diff",
  140. "WorkDir": "/var/lib/docker/overlay2/bc9ef8c119903b79ec581081d835c447ce00b72eb70b07b45d14b3dde7a37c51/work"
  141. },
  142. "Name": "overlay2"
  143. },
  144. "Mounts": [],
  145. "Config": {
  146. "Hostname": "ad7cc45c81ff",
  147. "Domainname": "",
  148. "User": "",
  149. "AttachStdin": false,
  150. "AttachStdout": false,
  151. "AttachStderr": false,
  152. "ExposedPorts": {
  153. "80/tcp": {}
  154. },
  155. "Tty": false,
  156. "OpenStdin": false,
  157. "StdinOnce": false,
  158. "Env": [
  159. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  160. "NGINX_VERSION=1.15.9-1~stretch",
  161. "NJS_VERSION=1.15.9.0.2.8-1~stretch"
  162. ],
  163. "Cmd": [
  164. "nginx",
  165. "-g",
  166. "daemon off;"
  167. ],
  168. "ArgsEscaped": true,
  169. "Image": "nginx",
  170. "Volumes": null,
  171. "WorkingDir": "",
  172. "Entrypoint": null,
  173. "OnBuild": null,
  174. "Labels": {
  175. "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
  176. },
  177. "StopSignal": "SIGTERM"
  178. },
  179. "NetworkSettings": {
  180. "Bridge": "",
  181. "SandboxID": "c107fe699256ce2babfe253697e8920386d06d86dae4d91be13c0b6cca00aa08",
  182. "HairpinMode": false,
  183. "LinkLocalIPv6Address": "",
  184. "LinkLocalIPv6PrefixLen": ,
  185. "Ports": {
  186. "80/tcp": [
  187. {
  188. "HostIp": "0.0.0.0",
  189. "HostPort": ""
  190. }
  191. ]
  192. },
  193. "SandboxKey": "/var/run/docker/netns/c107fe699256",
  194. "SecondaryIPAddresses": null,
  195. "SecondaryIPv6Addresses": null,
  196. "EndpointID": "88fa96a128cc924a9117cae0f720609ed70cad716892da3baf598e7f58a03ecc",
  197. "Gateway": "172.17.0.1",
  198. "GlobalIPv6Address": "",
  199. "GlobalIPv6PrefixLen": ,
  200. "IPAddress": "172.17.0.2",
  201. "IPPrefixLen": ,
  202. "IPv6Gateway": "",
  203. "MacAddress": "02:42:ac:11:00:02",
  204. "Networks": {
  205. "bridge": {
  206. "IPAMConfig": null,
  207. "Links": null,
  208. "Aliases": null,
  209. "NetworkID": "43fd51e168684e9ecd3684cf50beff2305983c747083d35e2b8a04d3470d775b",
  210. "EndpointID": "88fa96a128cc924a9117cae0f720609ed70cad716892da3baf598e7f58a03ecc",
  211. "Gateway": "172.17.0.1",
  212. "IPAddress": "172.17.0.2",
  213. "IPPrefixLen": ,
  214. "IPv6Gateway": "",
  215. "GlobalIPv6Address": "",
  216. "GlobalIPv6PrefixLen": ,
  217. "MacAddress": "02:42:ac:11:00:02",
  218. "DriverOpts": null
  219. }
  220. }
  221. }
  222. }
  223. ]

7、停止Nginx应用

  1. [root@localhost ~]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. ad7cc45c81ff nginx "nginx -g 'daemon of…" seconds ago Up seconds 0.0.0.0:->/tcp myNginx
  4. [root@localhost ~]# docker stop ad7cc45c81ff
  5. ad7cc45c81ff

8、查看Nginx进程,访问80端口

  1. [root@localhost ~]# ps -ef|grep nginx
  2. root : pts/ :: grep --color=auto nginx
  3. [root@localhost ~]# curl http://localhost:80/
  4. curl: () Failed connect to localhost:; Connection refused

9、删除Nginx应用Container(一般需要先停止后才能删除,强制删除使用 docker rm -f xxx)

  1. [root@localhost ~]# docker stop ad7cc45c81ff
  2. ad7cc45c81ff
  3. [root@localhost ~]# docker rm ad7cc45c81ff
  4. ad7cc45c81ff

10、Docker的Nginx应用映射到主机8899端口

  1. [root@localhost ~]# curl http://localhost:8899/
  2. curl: () Failed connect to localhost:; Connection refused
  3. [root@localhost ~]# docker run -p : --name myNginx -d nginx
  4. 598c5f3d52e0511480eebb031c2cdee05b155054edd014ca22ca1bef49d62867
  5. [root@localhost ~]# curl http://localhost:8899/
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <title>Welcome to nginx!</title>
  10. <style>
  11. body {
  12. width: 35em;
  13. margin: auto;
  14. font-family: Tahoma, Verdana, Arial, sans-serif;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <h1>Welcome to nginx!</h1>
  20. <p>If you see this page, the nginx web server is successfully installed and
  21. working. Further configuration is required.</p>
  22.  
  23. <p>For online documentation and support please refer to
  24. <a href="http://nginx.org/">nginx.org</a>.<br/>
  25. Commercial support is available at
  26. <a href="http://nginx.com/">nginx.com</a>.</p>
  27.  
  28. <p><em>Thank you for using nginx.</em></p>
  29. </body>
  30. </html>

Docker部署Nginx应用(2)的更多相关文章

  1. Docker部署Nginx并修改配置文件

    Docker部署Nginx并修改配置文件 一.拉取nginx镜像 docker pull nginx 二.在宿主机中创建挂载目录 mkdir -p /data/nginx/{conf,conf.d,h ...

  2. docker(部署常见应用):docker部署nginx

    上回说到centos安装docker. 这次用实战,docker部署运行常见的应用. docker常用命令 参看:docker命令大全.这里不做赘述. docker部署nginx 1.docker h ...

  3. 使用docker部署nginx+tomcat架构(3):使用docker-compose简化部署操作

    经历了之前的两篇,我们已经大体上了解了docker部署容器的过程. 使用docker部署nginx+tomcat架构 使用docker部署nginx+tomcat架构():访问mysql数据库 不过, ...

  4. 使用docker部署nginx+tomcat架构(2):访问mysql数据库

    上一篇完成了通过docker部署nginx+tomcat的基础软件架构,但是距离一个真正可用的软件架构还差得很远.其中最重要的一点是缺少数据库这个角色的存在,那么本篇就来完善这一点. 废话少说,直接进 ...

  5. 【原创】大数据基础之Mesos+Marathon+Docker部署nginx

    一 安装 安装docker:https://www.cnblogs.com/barneywill/p/10343091.html安装mesos:https://www.cnblogs.com/barn ...

  6. docker 部署nginx 使用keepalived 部署高可用

    一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故 ...

  7. docker 部署 nginx+php+mysql

    系统:centos7 使用root账户 开放80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 安装docker yum ins ...

  8. 【转载】Docker部署nginx并修改配置文件

    docker 部署个nginx docker run \ --name nginx-health-web-pc \ -d -p 6800:80 \ -v /usr/docker/nginx/html: ...

  9. 使用docker部署nginx+tomcat架构

    架构说明: 使用nginx+tomcat实现动态/静态(资源请求)分离和负载均衡. 参考文档: https://www.runoob.com/docker/docker-tutorial.html 配 ...

随机推荐

  1. MySQL 存储过程 -流程控制的使用

    #五.流程控制的使用 #1.IF 使用 create PROCEDURE iftest1() BEGIN DECLARE a int DEFAULT 10; -- IF (a>1 &&a ...

  2. [GO]定时器的停止和重置

    package main import ( "time" "fmt" ) func main() { timer := time.NewTimer( * tim ...

  3. libxml2

    http://www.xmlsoft.org/downloads.html   建议直接用openscenegraph下载的3rdparty:http://www.openscenegraph.org ...

  4. 手动安装Chrome截屏控件扩展-Xproer.ScreenCapture(ScreenCapture.crx)

    1.打开扩展面板,在地址栏中输入 chrome://extensions   或通过"扩展程序"菜单打开   2.将ScreenCapture.crx拖拽到此面板中   3.选择添 ...

  5. form action 相对路径出问题

    http://www.w3chtml.com/html5/tag/base.html <base> 标签为页面上的所有链接规定默认地址或默认目标. 通常情况下,浏览器会从当前文档的 URL ...

  6. Tango Java API常数

    Tango Java API Constants常数 Constant Field Values常数字段值 Contents com.google.* com.google.* com.google. ...

  7. FileInputStream和FileOutStream的使用——文件字节输入/输出流

    最近又退回到java EE的学习,这篇博客就来讲解一下字节流中最重要的两个类FileInputStream和FileOutputStream的用法: FileInputStream:全称是文件字节输入 ...

  8. DLL的概念、dll导出类(转贴)

    1. DLL的概念DLL(Dynamic Linkable Library),动态链接库,可以向程序提供一些函数.变量或类.这些可以直接拿来使用.静态链接库与动态链接库的区别:(1)静态链接库与动态链 ...

  9. 谷歌三大核心技术(一)Google File System中文版

    http://www.open-open.com/lib/view/open1328763454608.html

  10. map的回调函数

    问题:--js   (['1','2','3']).map(parseInt) 第一眼看到这个题目的时候,脑海跳出的答案是 [1, 2, 3],但是真正的答案是[1, NaN, NaN]. 首先让我们 ...