社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
[root@iz2ze62mggaeloz5x6ucurz ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 11197 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1578 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 702 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 500 [OK]
webdevops/php-nginx Nginx with PHP-FPM 124 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 124
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 94 [OK]
bitnami/nginx Bitnami nginx Docker Image 65 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 58
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 50 [OK]
tobi312/rpi-nginx NGINX on Raspberry Pi / ARM 25 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 17
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 14 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 13 [OK]
wodby/drupal-nginx Nginx for Drupal container image 12 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 10
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 7
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 4
1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]
mailu/nginx Mailu nginx frontend 3 [OK]
travix/nginx NGinx reverse proxy 2 [OK]
toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
wodby/nginx Generic nginx 0 [OK]
[root@iz2ze62mggaeloz5x6ucurz ~]#
[root@iz2ze62mggaeloz5x6ucurz ~]# docker pull nginx
[root@iz2ze62mggaeloz5x6ucurz ~]# docker images nginx
[root@iz2ze62mggaeloz5x6ucurz ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liuguangyuan/ubuntu v2 41405366c114 8 days ago 137MB
nginx latest 2bcb04bdb83f 13 days ago 109MB
hello-world latest fce289e99eb9 3 months ago 1.84kB
ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
training/webapp latest 6fae60ef3446 3 years ago 349MB
[root@iz2ze62mggaeloz5x6ucurz ~]# mkdir -p /data/nginx/{conf,conf.d,html,logs}
[root@iz2ze62mggaeloz5x6ucurz ~]vim /data/nginx/conf/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
[root@iz2ze62mggaeloz5x6ucurz ~]vim /data/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /data/nginx/html;
# root /usr/nginx/html;
index index.html index.htm;
autoindex on;
try_files $uri /index/index/page.html;
#try_files $uri /index/map/page.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
#将容器中nginx的80端口映射到本地的80端口
[root@iz2ze62mggaeloz5x6ucurz ~]docker run --name nginx-d -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest
[root@iz2ze62mggaeloz5x6ucurz ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7d63ec031e2 nginx:latest "nginx -g 'daemon of…" 18 hours ago Up 17 hours 0.0.0.0:80->80/tcp nginx
#如果启动失败使用docker logs 查看日志
[root@iz2ze62mggaeloz5x6ucurz ~]#docker logs e7d63ec031e2
#是容器内的nginx配置与挂载的目录不一致 进入容器内
[root@iz2ze62mggaeloz5x6ucurz ~]# docker exec -it nginx /bin/bash
root@e7d63ec031e2:/# apt-get update #更新docker 源
root@e7d63ec031e2:/#apt-get install vim #速度慢请配置国内镜像
#重启docker nginx
[root@iz2ze62mggaeloz5x6ucurz ~]# docker restart nginx
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!