码迷,mamicode.com
首页 > Web开发 > 详细

使用Docker构建nginx静态网站

时间:2019-02-04 01:15:44      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:local   端口   dex   daemon   apt-get   res   文件   type   stream   

1. 建Dockerfile:

FROM ubuntu:14.04
MAINTAINER Marc LAW "zunly@hotmail.com"
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静态网站

标签:local   端口   dex   daemon   apt-get   res   文件   type   stream   

原文地址:https://www.cnblogs.com/Montauk/p/10351265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!