参考源

https://www.bilibili.com/video/BV1og4y1q7M4?spm_id_from=333.999.0.0

https://www.bilibili.com/video/BV1kv411q7Qc?spm_id_from=333.999.0.0

版本

本文章基于 Docker 20.10.11


部署 Nginx 可以参考 Docker Hub 官方文档:https://hub.docker.com/_/nginx

下载镜像

[root@sail home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
e5ae68f74026: Pull complete
21e0df283cd6: Pull complete
ed835de16acd: Pull complete
881ff011f1c9: Pull complete
77700c52c969: Pull complete
44be98c0fab6: Pull complete
Digest: sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

查看镜像

[root@sail home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f652ca386ed1 7 days ago 141MB

运行镜像

[root@sail home]# docker run -d --name=nginx01 -p 3344:80 nginx
f58fb3ed8c5587d2c28567c865759438e449f2fd65889f2910286b9cd74debec
[root@sail home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f58fb3ed8c55 nginx "/docker-entrypoint.…" 23 seconds ago Up 22 seconds 0.0.0.0:3344->80/tcp nginx01

测试验证

使用 curl 命令可以模拟网页访问,以此来测试 Nginx 启动情况。

[root@sail home]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>

外网访问测试

如果是使用阿里云服务器,需要先开启端口。

使用阿里云的公网 IP 即可进行访问。

出现此页面,即代表 Nginx 部署成功。

查看启动的容器

[root@sail home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f58fb3ed8c55 nginx "/docker-entrypoint.…" 12 minutes ago Up 12 minutes 0.0.0.0:3344->80/tcp nginx01

查看容器中 Nginx 目录

[root@sail home]# docker exec -it nginx01 /bin/bash
root@f58fb3ed8c55:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@f58fb3ed8c55:/# cd /etc/nginx
root@f58fb3ed8c55:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params

如此,如果需要修改 Nginx 的配置即可修改 nginx.conf 文件实现。

不过如果每次修改都要进入容器后再进行操作,是很繁琐的事,还是更推荐使用容器卷技术

详情见:Docker 12 数据卷

部署原理

最新文章

  1. 在本地调试移动设备上的页面——神器weinre介绍
  2. 关于baseflight cleanflight naze32不能解锁的办法
  3. Enterprise Solution 开发框架功能点
  4. 最好的vim教程莫过于vimtutor
  5. Flash Decompiler
  6. [Effective JavaScript笔记]第1条:了解使用的js版本
  7. Rotate String
  8. [ios][opengles]opengles在ios上的透明问题
  9. iOS-JS交互 (WebViewJavascriptBridge)
  10. leetcode-173:Binary Search Tree Iterator(Java)
  11. Cocos2d-x CCEditBox &amp; CCTextFieldTTF
  12. 基本 XAML 语法指南
  13. Qt中Ui名字空间以及setupUi函数的原理和实现 &lt;转&gt;
  14. NHibernate 的 ID 标识选择器
  15. selenium的Python使用(一)浏览器驱动的安装及使用
  16. python上下文管理器ContextLib及with语句
  17. 解决svn更新项目目录时“Error:svn: E155037: Previous operation has not finished; run &#39;cleanup&#39; if it was interrupted”的报错问题
  18. [Swift]LeetCode461. 汉明距离 | Hamming Distance
  19. Chrome添加Axure RP插件
  20. Android-Nexus5-命令刷机

热门文章

  1. R-CNN学习笔记
  2. ElasticSearch7.3学习(三十)----ES7.X SQL新特性解析及使用Java api实现sql功能
  3. .NET Core 企业微信回调配置
  4. SAP Display picture
  5. SAP 实例 3 Context Menus
  6. 编程技巧│提高 Javascript 代码效率的技巧
  7. JQuery select与radio的取值与赋值
  8. [LINUX] 像电影里的黑客一样用 terminal 作为日常开发
  9. EasyExcel导出创建Excel下拉框
  10. Maven配置【详细】