这篇文章主要介绍了Docker如何运行Nginx并挂载本地目录到镜像中的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Docker如何运行Nginx并挂载本地目录到镜像中文章都会有所收获,下面我们一起来看看吧。
1 从hup上pull镜像
docker pull Nginx
2 创建将要挂载的目录
mkdir -p /data/Nginx/{conf,conf.d,html,logs}
3 先要有配置文件才能启动容器
3.1 vim /data/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; }
3.2 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; #} }
4 启动容器
#将容器中Nginx的80端口映射到本地的81端口 docker run --name Nginx81 -d -p 81: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
5 查看启动的容器
[root@dc01 ~]# docker ps container id image command created status ports names fa56f865bd26 Nginx:latest "Nginx -g 'daemon of…" 4 weeks ago up 3 seconds 0.0.0.0:80->80/tcp vigilant_swirles [root@dc01 ~]#
6 网页访问Nginx
关于“Docker如何运行Nginx并挂载本地目录到镜像中”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Docker如何运行Nginx并挂载本地目录到镜像中”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程之家行业资讯频道。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。