dockerfile制作各应用镜像实例

目标:

例如:

  • 记录 dockerfile制作各应用镜像实例代码

应用实例:

  1. 搭建jar应用程序docker容器
    Dockerfile文件:
FROM java:8
MAINTAINER 126@126.net
COPY ./automation-1.0.0.jar /app/automation-1.0.0.jar
WORKDIR /app/logs/
WORKDIR /app/
ENV TZ=Asia/Shanghai
EXPOSE 81
CMD ["java","-jar","automation-1.0.0.jar","-Dfile.encoding=utf-8"]

构建镜像: docker build -t automation-docker .
构建成功后,启动容器:docker run -it -p 81:81 –name automation -d automation-docker
进入容器内部查看: docker exec -it automation /bin/bash

curl http://localhost:81/api地址访问

  1. 搭建war应用程序docker容器
FROM tomcat-alpine-pp2:8.5.51.16(tomcat根据实际变更)
RUN rm -rf /usr/local/tomcat/webapps/ROOT
ADD automation.war /usr/local/tomcat/webapps/automation.war
# 修改docker时区为东八区,规避应用运行时间与北京时间相差8小时问题  
ENV TZ=Asia/Shanghai 
EXPOSE 8081 
CMD ["/usr/local/tomcat/bin/catalina.sh","run"]
  1. npm nodejs生成dist资源打包至nginx:1.22容器
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,容器,运维)