【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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM