Docker 安装 Nginx

Reads: 767 Edit

Docker 安装 Nginx

Nginx 是一个高性能的 HTTP 和反向代理 web 服务器,同时也提供了 IMAP/POP3/SMTP 服务 。 1、查看可用的 Nginx 版本

访问 Nginx 镜像库地址: https://hub.docker.com/_/nginx?tab=tags。

可以通过 Sort by 查看其他版本的 Nginx,默认是最新版本 nginx:latest。

docker-nginx1

你也可以在下拉列表中找到其他你想要的版本:

docker-nginx2

此外,我们还可以用 docker search nginx 命令来查看可用版本:

[root@localhost ~]# docker search nginx
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                             Official build of Nginx.                        12332               [OK]                
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…   1698                                    [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of…   748                                     [OK]
linuxserver/nginx                 An Nginx container, brought to you by LinuxS…   83                                      
bitnami/nginx                     Bitnami nginx Docker Image                      73                                      [OK]
tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rtmp…   60                                      [OK]
nginxdemos/hello                  NGINX webserver that serves a simple page co…   34                                      [OK]
jc21/nginx-proxy-manager          Docker container for managing Nginx proxy ho…   31                                      
jlesage/nginx-proxy-manager       Docker container for Nginx Proxy Manager        30                                      [OK]
nginx/nginx-ingress               NGINX Ingress Controller for Kubernetes         22                                      
privatebin/nginx-fpm-alpine       PrivateBin running on an Nginx, php-fpm & Al…   19                                      [OK]
schmunk42/nginx-redirect          A very simple container to redirect HTTP tra…   17                                      [OK]
blacklabelops/nginx               Dockerized Nginx Reverse Proxy Server.          12                                      [OK]
centos/nginx-18-centos7           Platform for running nginx 1.8 or building n…   12                                      
raulr/nginx-wordpress             Nginx front-end for the official wordpress:f…   12                                      [OK]
nginxinc/nginx-unprivileged       Unprivileged NGINX Dockerfiles                  11                                      
centos/nginx-112-centos7          Platform for running nginx 1.12 or building …   10                                      
nginx/nginx-prometheus-exporter   NGINX Prometheus Exporter                       9                                       
1science/nginx                    Nginx Docker images that include Consul Temp…   5                                       [OK]
sophos/nginx-vts-exporter         Simple server that scrapes Nginx vts stats a…   5                                       [OK]
mailu/nginx                       Mailu nginx frontend                            5                                       [OK]
pebbletech/nginx-proxy            nginx-proxy sets up a container running ngin…   2                                       [OK]
ansibleplaybookbundle/nginx-apb   An APB to deploy NGINX                          1                                       [OK]
wodby/nginx                       Generic nginx                                   0                                       [OK]
centos/nginx-110-centos7          Platform for running nginx 1.10 or building …   0                                       
[root@localhost ~]# 

2、取最新版的 Nginx 镜像

这里我们拉取官方的最新版本的镜像:

$ docker pull nginx:latest

aaa5024736

3、查看本地镜像

使用以下命令来查看是否已安装了 nginx:

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              231d40e811cd        3 weeks ago         126MB
centos              centos7             5e35e350aded        4 weeks ago         203MB
ubuntu              latest              775349758637        6 weeks ago         64.2MB

在上图中可以看到我们已经安装了最新版本(latest)的 nginx 镜像。

4、运行容器

安装完成后,我们可以使用以下命令来运行 nginx 容器:

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

参数说明:

  • --name nginx-test:容器名称。

  • -p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。

  • -d nginx: 设置容器在在后台一直运行。

ccc4942

5、安装成功

最后我们可以通过浏览器可以直接访问 8080 端口的 nginx 服务:

nginx91215025111

关于作者

王硕,十年软件开发经验,业余产品经理,精通Java/Python/Go等,喜欢研究技术,著有《PyQt快速开发与实战》《Python 3.* 全栈开发》,多个业余开源项目托管在GitHub上,欢迎微博交流:


Comments

Make a comment

www.ultrapower.com ,王硕的博客,专注于研究互联网产品和技术,提供中文精品教程。 本网站与其它任何公司及/或商标无任何形式关联或合作。