使用Docker構建nginx靜態網站
阿新 • • 發佈:2019-02-04
eve node localhost html keepalive nginx 主機 bsp 文件
1. 建Dockerfile:
FROM ubuntu:14.04 MAINTAINER Marc LAW "[email protected]" ENV REFRESHED_AT 2019-02-03 RUN apt-get -yqq update && apt-get -yqq install nginx RUN mkdir -p /var/www/html/website ADD nginx/global.conf /etc/nginx/conf.d/ ADD nginx/nginx.conf /etc/nginx/nginx.conf EXPOSE 80
從ubuntu中拉取nginx
2. global.conf跟nginx.conf文件:
[m@localhost NginxWebSite]$ cat nginx/nginx.conf user www-data; worker_processes 4; pid /run/nginx.pid; daemon off; events { } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log/var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; }
[m@localhost NginxWebSite]$ cat nginx/global.conf server { listen 0.0.0.0:80; server_name _; root /var/www/html/website; index index.html index.htm; access_log/var/log/nginx/default_access.log; error_log /var/log/nginx/default_error.log; }
3. 構建鏡像:
$ sudo docker build -t jamtur01/nginx .
4. 啟動鏡像:
$ sudo docker run -d -p 80 --name website -v $PWD/website:/var/www/html/website jamtur01/nginx nginx
-v 命令把宿主機的$PWD/website目錄映射到容器內的nginx的html根目錄.
5. 關掉selinux, 在$PWD/website裏面建index.html文件, 並根據容器的映射端口(隨機)測試訪問吧.
使用Docker構建nginx靜態網站