Docker 安装 Nginx 入门教程

2023-07-0910:38:46服务器及运维Comments1,632 views字数 1186阅读模式

Nginx 是一个高性能的 HTTP 和反向代理 web 服务器,同时也提供了 IMAP/POP3/SMTP 服务 。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

1、查看可用的 Nginx 版本

访问 Nginx 镜像库地址: https://hub.docker.com/_/nginx?tab=tags文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

可以通过 Sort by 查看其他版本的 Nginx,默认是最新版本 nginx:latest文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

Docker 安装 Nginx 入门教程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

你也可以在下拉列表中找到其他你想要的版本:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

Docker 安装 Nginx 入门教程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

此外,我们还可以用  docker search nginx 命令来查看可用版本:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

$ docker search nginx
NAME                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                     Official build of Nginx.                        3260      [OK]       
jwilder/nginx-proxy       Automated Nginx reverse proxy for docker c...   674                  [OK]
richarvey/nginx-php-fpm   Container running Nginx + PHP-FPM capable ...   207                  [OK]
million12/nginx-php       Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS...   67                   [OK]
maxexcloo/nginx-php       Docker framework container with Nginx and ...   57                   [OK]
...

2、取最新版的 Nginx 镜像

这里我们拉取官方的最新版本的镜像:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

$ docker pull nginx:latest

Docker 安装 Nginx 入门教程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

3、查看本地镜像

使用以下命令来查看是否已安装了 nginx:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

$ docker images

Docker 安装 Nginx 入门教程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

在上图中可以看到我们已经安装了最新版本(latest)的 nginx 镜像。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

4、运行容器

安装完成后,我们可以使用以下命令来运行 nginx 容器:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

$ docker run --name nginx-test -8080:80 -d nginx

参数说明:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

  • --name nginx-test:容器名称。 
  • -p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
  • -d nginx: 设置容器在在后台一直运行。

Docker 安装 Nginx 入门教程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

5、安装成功

最后我们可以通过浏览器可以直接访问 8080 端口的 nginx 服务:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

Docker 安装 Nginx 入门教程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50774.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/50774.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定