docker安装nginx
1、下载镜像,选择稳定版
docker pull nginx:stable
2、查看镜像
docker images
3、创建挂载目录
4、编写配置文件nginx.conf放在主机/home/nginx/conf目录下(挂载的目录),我使用9000作为http的端口
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; 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; server{ listen 9000; server_name localhost; charset utf-8; location / { root /usr/share/nginx/html/; try_files $uri $uri/ =404; index index.html index.htm; } #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 html; } location /web/ { alias /usr/share/nginx/web/; index index.html; try_files $uri $uri/ /index.html =404; } } }
5、编写启动容器的脚本
docker run
-p 9000:9000
–name nginx
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /home/nginx/log:/var/log/nginx
-v /home/nginx/html:/usr/share/nginx/html
-v /home/nginx/web:/usr/share/nginx/web
-d nginx:stable
6、整体目录如下
7、执行启动脚本
8、查看容器启动
9、访问效果