如何将vue生成的html打包为镜像呢?
下文笔者讲述将一个前端文件制作为Docker镜像的方法分享,如下所示
前端页面之Dockerfile简介说明
Dockerfile文件指南
实现思路: 1.使用npm node.js将生成的dist资源信息打包至nginx:1.22原始容器上 2.编写Dockerfile 3.生成docker镜像信息例:
前端页面之Dockerfile简介说明
//Dockerfile文件 FROM nginx:1.22.0-alpine(nginx根据实际变更) RUN rm -rf /usr/share/nginx/html/manage COPY ./manage/dist /usr/share/nginx/html/manage #ADD ./dist.tar /usr/share/nginx/html/ RUN ls -al && pwd #conf是归档文件 COPY ./conf/default.conf /etc/nginx/conf.d/default.conf COPY ./conf/nginx.conf /etc/nginx/nginx.conf WORKDIR /usr/share/nginx/ RUN ls -al && pwd 修改docker时区为东八区,规避应用程序和北京时间相差8小时问题 ENV TZ=Asia/Shanghai EXPOSE 31727 CMD ["nginx", "-g", "daemon off;"] //nginx.conf文件 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; proxy_buffer_size 128k; proxy_buffers 32 64k; proxy_busy_buffers_size 256k; client_max_body_size 2048m; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json image/jepg image/gif image/png image/jpg; gzip_disable "MSIE[1-6]\."; gzip_vary on; proxy_ignore_client_abort on; include /etc/nginx/conf.d/*.conf; } //default.conf文件 server { listen 81; listen [::]:81; server_name localhost; access_log /var/log/nginx/accessservice.log; error_log /var/log/nginx/errorsservice.log; location / { root /usr/share/nginx/html/manage; index index.html index.htm; proxy_set_header X-Forward-For $remote_addr; try_files $uri $uri/ /index.html; } } 注意事项: 当同时发布dist目录下两个不同web资源项目(如manage、monitor) //可追加monitor配置: location /monitor { alias /usr/share/nginx/html/monitor; index index.html index.htm; proxy_set_header X-Forward-For $remote_addr; try_files $uri $uri/ /index.html; } //生成Docker镜像,启动运行 构建镜像: docker build -t automation-docker . 构建成功后,启动容器:docker run -it -p 81:81 –name automation -d automation-docker 进入容器内部查看: docker exec -it automation /bin/bash curl ttp://localhost:81/api地址访问相关阅读:
Dockerfile文件指南
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。