Docker 06 部署Nginx

参考源

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 数据卷

部署原理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天航星

感谢你的鼓励和认可

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值