docker构建nginx

1 准备default.conf

      

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    access_log  /var/log/nginx/host.access.log  main;
    error_log  /var/log/nginx/error.log  error;

    location / {
        root   /usr/share/nginx/html;
        index  historyReloadCanvas.html; //可改成自己的首页
        try_files $uri $uri/ /index.html;
    }
    

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

2 Dcokerfile

    

FROM nginx:1.16.1-alpine                   基础镜像
COPY ./  /usr/share/nginx/html/            将目录copy到html下
COPY ./default.conf /etc/nginx/conf.d/default.conf     替换nginx 的配置文件
RUN chmod -R 755 /usr/share/nginx/html       复制权限

  

3 docker build

    docker build -f ./Dockerfile -t imagename .                       -f 指定dockerfile文件  -t 指定镜像名称    注意后面的点 表示当前目录打包镜像

   docker push imagename:latest     推送镜像

原文地址:https://www.cnblogs.com/syscn/p/13692000.html