docker 部署 nginx实例

主要知识点:

  1. 前台后台,容器与虚拟机之间的区别,容器中的应用都应该以前台执行
  2. 配置文件的挂载

编辑Dockerfile文件

FROM nginx

COPY fronts /root/fronts

CMD nginx -g "daemon off;"

创建镜像

$docker build -t fronts:v1 .

编辑配置文件

原配置文件,修改即可

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #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;
    }

}

启动容器

这里启动容器我们有两个选择,一是覆盖/etc/nginx/nginx.conf根配置文件,
二是覆盖/etc/nginx/conf.d/default.conf文件。相比之下二选择更优,指责划分更加清晰。

docker run  -p 8000:80 -v /absolute/path/nginx.conf:/etc/nginx/conf.d/default.conf -d nginx

猜你喜欢

转载自www.cnblogs.com/zenan/p/10820634.html
今日推荐