需求

做一个简单的Nginx web 服务,映射出他的 http服务就OK

操作

首先 docker hub 搜索 nginx 找到自己想用的版本
https://hub.docker.com/_/nginx
image.png

根据自己的需求选择版本,我这边直接拉最新的版本就ok。 docker hub 也提示了如何使用这个镜像。
许多详细的操作都可以根据 docker hub 上的提示进行操作。

  1. [root@localhost /]# docker pull nginx
  2. Using default tag: latest
  3. latest: Pulling from library/nginx
  4. b380bbd43752: Pull complete
  5. fca7e12d1754: Pull complete
  6. 745ab57616cb: Pull complete
  7. a4723e260b6f: Pull complete
  8. 1c84ebdff681: Pull complete
  9. 858292fd2e56: Pull complete
  10. Digest: sha256:644a70516a26004c97d0d85c7fe1d0c3a67ea8ab7ddf4aff193d9f301670cf36
  11. Status: Downloaded newer image for nginx:latest
  12. docker.io/library/nginx:latest
  13. [root@localhost /]# docker images
  14. REPOSITORY TAG IMAGE ID CREATED SIZE
  15. nginx latest 87a94228f133 9 days ago 133MB
  16. [root@localhost /]# docker run -itd --name nginx02 -p 11223:80 nginx
  17. 0bfe72c48e1d54773ca9f66223d7c22d9e0edfd038de65e9e148a343b3eb542b
  18. [root@localhost /]# docker ps
  19. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  20. 0bfe72c48e1d nginx "/docker-entrypoint.…" 3 seconds ago Up 2 seconds 0.0.0.0:11223->80/tcp, :::11223->80/tcp nginx02
  21. [root@localhost /]# curl localhost:11223
  22. <!DOCTYPE html>
  23. <html>
  24. <head>
  25. <title>Welcome to nginx!</title>
  26. <style>
  27. html { color-scheme: light dark; }
  28. body { width: 35em; margin: 0 auto;
  29. font-family: Tahoma, Verdana, Arial, sans-serif; }
  30. </style>
  31. </head>
  32. <body>
  33. <h1>Welcome to nginx!</h1>
  34. <p>If you see this page, the nginx web server is successfully installed and
  35. working. Further configuration is required.</p>
  36. <p>For online documentation and support please refer to
  37. <a href="http://nginx.org/">nginx.org</a>.<br/>
  38. Commercial support is available at
  39. <a href="http://nginx.com/">nginx.com</a>.</p>
  40. <p><em>Thank you for using nginx.</em></p>
  41. </body>
  42. </html>
  43. [root@localhost /]#