Docker 安装 Nginx


1、取最新版的 Nginx 镜像
这里我们拉取官方的最新版本的镜像:
[root@docke ~]# docker pull nginx:latest
2、查看本地镜像
使用以下命令来查看是否已安装了 nginx:
[root@docke ~]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ad4c705f24d3 6 days ago 133.2 MB
3、运行容器
安装完成后,我们可以使用以下命令来运行 nginx 容器:
[root@docke ~]# docker run --name nginx-test -p 8080:80 --network bridge -d nginx
331f6385c47439011e178452ec255058b4941dc9eac02f4b75dd42819ddae254
参数说明:
--name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
-d nginx: 设置容器在在后台一直运行。
--network bridge : 网络模式为bridge
4、安装成功
最后我们可以通过浏览器可以直接访问 8080 端口的 nginx 服务
[root@docke ~]# curl 192.168.0.11:8080
<!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>

5、查看nginx版本

[root@docke ~]# docker exec -it nginx-test /bin/bash

root@331f6385c474:/# nginx -v
nginx version: nginx/1.21.3

首页文件

root@331f6385c474:/# find  / -name *.html

root@331f6385c474:/# cd /usr/share/nginx/html/

posted @ 2021-09-16 10:48  落樰兂痕  阅读(37)  评论(0编辑  收藏  举报