Docker安装Nginx

1、搜索Nginx(建议在网站搜索,这里是用命令搜索的)

[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        14958     [OK]       
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   2032                 [OK]
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   813                  [OK]
jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ho…   196                  
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   148                  
tiangolo/nginx-rtmp                Docker image with Nginx using the nginx-rtmp…   127                  [OK]
jlesage/nginx-proxy-manager        Docker container for Nginx Proxy Manager        115                  [OK]
alfg/nginx-rtmp                    NGINX, nginx-rtmp-module and FFmpeg from sou…   99                   [OK]
bitnami/nginx                      Bitnami nginx Docker Image                      95                   [OK]
jasonrivers/nginx-rtmp             Docker images to host RTMP streams using NGI…   90                   [OK]
nginxdemos/hello                   NGINX webserver that serves a simple page co…   70                   [OK]
privatebin/nginx-fpm-alpine        PrivateBin running on an Nginx, php-fpm & Al…   53                   [OK]
nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   52                   
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  36                   
staticfloat/nginx-certbot          Opinionated setup for automatic TLS certs lo…   23                   [OK]
schmunk42/nginx-redirect           A very simple container to redirect HTTP tra…   19                   [OK]
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN…   18                   
centos/nginx-112-centos7           Platform for running nginx 1.12 or building …   15                   
centos/nginx-18-centos7            Platform for running nginx 1.8 or building n…   13                   
raulr/nginx-wordpress              Nginx front-end for the official wordpress:f…   13                   [OK]
flashspys/nginx-static             Super Lightweight Nginx Image                   10                   [OK]
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   8                    [OK]
mailu/nginx                        Mailu nginx frontend                            8                    [OK]
ansibleplaybookbundle/nginx-apb    An APB to deploy NGINX                          2                    [OK]
wodby/nginx                        Generic nginx

2、安装Nginx

[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete
30afc0b18f67: Pull complete
596b1d696923: Pull complete
febe5bd23e98: Pull complete
8283eee92e2f: Pull complete
351ad75a6cfa: Pull complete
Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    d1a364dc548d   8 days ago     133MB
centos       latest    300e315adb2f   5 months ago   209MB

3、启动Nginx并修改内部端口号为3344(只要是开放端口就行),外部端口为40

# -d      后台运行
# --name  给容器命名
# -p      宿主机端口,容器内部端口
[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker run -d --name nginx01 -p 3344:80 nginx
a91204df9950f8347b5dc32633471e87dbe31ec3b858f155849b9f544d0dc5e2
[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
a91204df9950   nginx     "/docker-entrypoint.…"   9 seconds ago   Up 8 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01

4、测试是否启动成功

[root@iZbp1ce780a5j2zww8kl9hZ ~]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>
至此就可以在浏览器进行访问 如http://47.97.99.xx:3344/
端口暴露概念

5、进入容器

[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker exec -it nginx01 /bin/bash
root@a91204df9950:/# ls
bin  boot  dev    docker-entrypoint.d  docker-entrypoint.sh  etc    home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@a91204df9950:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@a91204df9950:/# cd /etc/nginx
root@a91204df9950:/etc/nginx# ls
conf.d    fastcgi_params    mime.types  modules  nginx.conf  scgi_params  uwsgi_params

6、退出容器

root@a91204df9950:/etc/nginx# exit
exit
[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
a91204df9950   nginx     "/docker-entrypoint.…"   15 minutes ago   Up 15 minutes   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker stop a91204df9950
a91204df9950
[root@iZbp1ce780a5j2zww8kl9hZ ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

思考问题:我们每次改动nginx配置文件,都需要进入容器内部? 十分的麻烦,我要是可以在容器外部提供一个映射路径,达到在容器修改文件名,容器内部就可以自动修改? -v 数据卷!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值