1. 建 Dockerfile:
从 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 文件, 并根据容器的映射端口 (随机) 测试访问吧.
来源: http://www.bubuko.com/infodetail-2944493.html