镜像体积优化
优化前构建镜像体积:1.2GB
优化后构建镜像体积:621.63 MB
优化思路,1.centos镜像体积太大,有几百MB,使用alpine版本体积更小。2.只需要jre即可,无需jdk。
优化前
Dockerfile
FROM centos:centos7 WORKDIR /mydocker/jdk #创建一个存放jdk的路径 RUN mkdir /mydocker/jdk/jdk11 #将jdk压缩包复制并解压到容器中/mydocker/jdk/jdk11 ADD jdk-11.0.18_linux-x64_bin.tar.gz /mydocker/jdk/jdk11 #配置java环境变量 ENV JAVA_HOME /mydocker/jdk/jdk11/jdk-11.0.18 ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ENV PATH $JAVA_HOME/bin:$PATH RUN yum -y update; yum clean all RUN yum -y install epel-release; yum clean all RUN yum -y install nodejs npm; yum clean all ADD . /mydocker/jdk RUN cd /mydocker/jdk; npm install EXPOSE 3000
yaml文件
version: "3" services: app: platform: linux/amd64 image: font_file_pick container_name: font_file_pick ports: - "3000:3000" build: context: ./ # 指定dockerfile文件的所在路径 dockerfile: Dockerfile # 指定Dockerfile文件名称 volumes: - ./:/home/node/app command: npm run start
优化后
Dockerfile
FROM eclipse-temurin:17-jre-alpine WORKDIR /work RUN apk add nodejs npm COPY . /work RUN cd /work && npm install EXPOSE 3000yaml文件
version: "3" services: app: platform: linux/amd64 image: font_file_pick container_name: font_file_pick ports: - "3000:3000" build: context: ./ # 指定dockerfile文件的所在路径 dockerfile: Dockerfile # 指定Dockerfile文件名称 command: npm run start
安装nodejs方式: https://nodejs.org/en/download/package-manager#alpine-linux
标签:jre,RUN,jdk,nodejs,mydocker,HOME,镜像,Dockerfile From: https://www.cnblogs.com/fengnovo/p/17257986.html