说明
本文在docker中实现了一个nginx静态服务器,尚未实现反向代理
前期准备
操作
拉取nginx:docker pull nginx
新建工作目录~/nginx
front_end 静态文件目录
Dockerfile 如下:
FROM nginx
COPY ./nginx.conf /etc/nginx/
WORDIR /static
COPY ./front_end /static
CMD nginx -g "daemon off;"
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
location / {
root /static;
}
}
}
构建镜像
sudo docker build -t nginx:test ~/nginx
运行容器
sudo docker run -p 8000:80 nginx:test
一些坑
nginx -g "daemon off;"
nginx -g 作用是指定全局配置项
daemon off 的意思就是不后台运行
这个很重要,因为docker会查看进程运行来判断容器状态
通过bash 运行nginx,nginx退出前台在后台运行
docker 一看bash没有运行东西,以为退出了,所以就关停了容器