Docker 安裝nginx

在docker啓動nginx,並修改相關配置php

1:查詢nginx鏡像 

docker search nginx
[root@iZbp1h2vcoigag0f1dn31mZ ~]# docker search nginx
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                             Official build of Nginx.                        11926               [OK]                
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…   1650                                    [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of…   740                                     [OK]
linuxserver/nginx                 An Nginx container, brought to you by LinuxS…   75                                      
bitnami/nginx                     Bitnami nginx Docker Image                      70                                      [OK]
tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rtmp…   53                                      [OK]
nginxdemos/hello                  NGINX webserver that serves a simple page co…   27                                      [OK]
jc21/nginx-proxy-manager          Docker container for managing Nginx proxy ho…   23                                      
nginx/nginx-ingress               NGINX Ingress Controller for Kubernetes         22                                      
jlesage/nginx-proxy-manager       Docker container for Nginx Proxy Manager        22                                      [OK]
schmunk42/nginx-redirect          A very simple container to redirect HTTP tra…   17                                      [OK]
privatebin/nginx-fpm-alpine       PrivateBin running on an Nginx, php-fpm & Al…   17                                      [OK]
blacklabelops/nginx               Dockerized Nginx Reverse Proxy Server.          12                                      [OK]
centos/nginx-18-centos7           Platform for running nginx 1.8 or building n…   11                                      
centos/nginx-112-centos7          Platform for running nginx 1.12 or building …   10                                      
nginxinc/nginx-unprivileged       Unprivileged NGINX Dockerfiles                  9                                       
nginx/nginx-prometheus-exporter   NGINX Prometheus Exporter                       6                                       
sophos/nginx-vts-exporter         Simple server that scrapes Nginx vts stats a…   5                                       [OK]
1science/nginx                    Nginx Docker images that include Consul Temp…   5                                       [OK]
mailu/nginx                       Mailu nginx frontend                            3                                       [OK]
pebbletech/nginx-proxy            nginx-proxy sets up a container running ngin…   2                                       [OK]
travix/nginx                      NGinx reverse proxy                             2                                       [OK]
centos/nginx-110-centos7          Platform for running nginx 1.10 or building …   0                                       
wodby/nginx                       Generic nginx                                   0                                       [OK]
ansibleplaybookbundle/nginx-apb   An APB to deploy NGINX        
OFFICIAL  表示官方的
其餘的是經過第三方進行封裝的

2:拉去鏡像
docker pull nginx
[root@iZbp1h2vcoigag0f1dn31mZ ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
1ab2bdfe9778: Pull complete 
a17e64cfe253: Pull complete 
e1288088c7a8: Pull complete 
Digest: sha256:53ddb41e46de3d63376579acf46f9a41a8d7de33645db47a486de9769201fec9
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@iZbp1h2vcoigag0f1dn31mZ ~]# 

 

3:啓動nginx鏡像容器html

[root@iZbp1h2vcoigag0f1dn31mZ ~]# docker run --name test-nginx -p 80:80 -d nginx
e359a74aa8c386b3afe3c30472846c3a15f108b4368ea9fa30b974b14f6019cb

--name 容器名稱linux

-p 端口綁定 其中:前面的是本地當前服務器端口 ,冒號後面的時候容器nginx訪問端口 nginx

-d 使用後臺啓動web

直接使用瀏覽器訪問當前服務器ip地址便可看到nginx服務。docker

 

4:進入訪問內部容器 centos

docker exec -it test-nginx bash
[root@iZbp1h2vcoigag0f1dn31mZ /]# docker exec -it test-nginx bash
root@e359a74aa8c3:/# 

此時已經進入容器內部瀏覽器

nginx是docker內部已經設置好的,bash

nginx.conf 文件目錄 /etc/nginx/nginx.conf服務器

html文件目錄 /usr/share/nginx/html

log文件目錄 /var/log/nginx/access.log

 

參考nginx參數對nginx進行配置修改。具體根據本身需求調整

注:通常狀況下非最佳實現方案。

 

5:磁盤掛載

-v ~/nginx/www:/usr/share/nginx/html 
docker run --name test-nginx3 -p 8080:80 -d -v ~/nginx/www:/usr/share/nginx/html  nginx 

將宿主機磁盤映射到docker虛擬機內部

-v path1:path2  其中path1是宿主機磁盤地址 path2是docker映射虛擬磁盤地址

能夠定義多個 -v 映射多個文件夾

做用:能夠使用一套環境啓動多個服務。

 

6:從新載入 NGINX

docker kill -s HUP test-nginx
[root@iZbp1h2vcoigag0f1dn31mZ /]# docker kill -s HUP test-nginx
test-nginx
 

7:重啓nginx容器

docker restart container-name

[root@iZbp1h2vcoigag0f1dn31mZ /]# docker restart test-nginx
test-nginx

 

 

 至此,docker使用nginx的簡單操做已經完成。

相關文章
相關標籤/搜索