微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Docker 06 部署Nginx

部署 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>

外网访问测试

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

image

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

image

至此,即代表 Nginx 部署成功。

查看容器中 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 文件实现。

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

部署原理

image

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐