zoukankan      html  css  js  c++  java
  • 【docker小记】docker打包nginx

    缘由:AgentHub需要每个Agent打包一个前端页面的docker镜像

    采取的是用nginx作为服务器,环境是centos7

    制作镜像

    安装docker

    yum -y install docker

    启动docker

    systemctl start docker

    目录结构

    我是放在/home/jarjune/目录下,

    docker_nginx

    其中,

    • /conf是放nginx配置文件
    • Dockerfile是制作镜像的文件
    • /images是存放最后生成的镜像
    • resource是存放前端页面

    nginx.conf

    #user nobody;
    worker_processes  1;
    
    events {
      worker_connections  1024;
    }
    
    http {
      include   mime.types;
      default_type  application/octet-stream;
    
      sendfile  on;
      keepalive_timeout 65;
    
      gzip  on;
    
      server {
    
        #error_page 404 /404.html;
        error_page  500 502 503 504 /50x.html;
    
        location = /50x.html { 
          root html;
        }
    
        listen 7777;
        server_name test.com;
    
        location ~ .*.(css|js|swf|html|htm|pdf)$ { 
          add_header Cache-Control no-store;
          #add_header Content-Security-Policy upgrade-insecure-requests;
          root /var/www/html;
          autoindex on;
          index index.html index.htm;
        }
        location / {
          charset utf-8;
          root  /var/www/html;
          index index.html index.htm index.shtml;
        }
      }
    }
    

    Dockerfile

    # Base images 基础镜像
    FROM nginx:latest
    
    #MAINTAINER 维护者信息
    MAINTAINER robot robot@yunqiacademy.org
    
    ENV RUN_USER nginx
    ENV RUN_GROUP nginx
    ENV DATA_DIR /var/www/html #ADD
    #RUN 执行以下命令
    RUN mkdir -p /var/www/html
    
    #COPY
    COPY ./resource/ /var/www/html 
    COPY ./conf/nginx.conf /etc/nginx
    
    #EXPOSE 映射端口
    EXPOSE 7777
    
    #CMD 运行以下命令
    CMD ["nginx", "-g", "daemon off;"]
    

    生成镜像

    docker build --rm --tag nginx_webapp:1.0.0 .

    查看镜像

    docker images

    启动镜像

    docker run -d -p 81:7777 -it nginx_webapp:1.0.0 /bin/bash

    查看镜像id(container id)

    docker ps

    进入镜像

    docker attach 81ad9dbc2a7a

    运行nginx

    nginx

    测试是否成功

    浏览器输入地址

    打包

    docker save -o images/nginx_webapp_1.0.0.tar nginx_webapp:1.0.0

  • 相关阅读:
    vue 文件上传
    小程序tab切换
    css实现内凹圆角样式
    vue elemnt upload 提交带参数
    解决在style添加scoped属性的情况下改变插件的css样式无效
    小程序自定义头部导航栏
    icon使用
    JavaWeb和WebGIS学习笔记(三)——GeoServer 发布shp数据地图
    ArcGIS建筑物简化和建筑物群聚合算法实验
    Java web与web gis学习笔记(二)——百度地图API调用
  • 原文地址:https://www.cnblogs.com/jarjune/p/10173680.html
Copyright © 2011-2022 走看看