#1.指定基础镜像,并且必须是第一条指令
FROM alpine:latest
#2.指明该镜像的作者和其电子邮件
MAINTAINER ChenYao "1103613624@qq.com"
#3.在构建镜像时,指定镜像的工作目录,之后的命令都是基于此工作目录,如果不存在,则会创建目录
WORKDIR /xiaoye/jdk
#4.将一些安装包复制到镜像中,语法:ADD/COPY <src>... <dest>
## ADD与COPY的区别:ADD复制并解压,COPY仅复制
ADD jdk-8u221-linux-x64.tar.gz /xiaoye/jdk/
## glibc安装包如果从网络下载速度实在是太慢了,先提前下载复制到镜像中
COPY glibc-2.29-r0.apk /xiaoye/jdk/
COPY glibc-bin-2.29-r0.apk /xiaoye/jdk/
COPY glibc-i18n-2.29-r0.apk /xiaoye/jdk/
#5.更新Alpine的软件源为阿里云,因为从默认官源拉取实在太慢了
RUN echo http://mirrors.aliyun.com/alpine/v3.10/main/ > /etc/apk/repositories && \
echo http://mirrors.aliyun.com/alpine/v3.10/community/ >> /etc/apk/repositories
RUN apk update && apk upgrade
#6.运行指定的命令
## Alpine linux为了精简本身并没有安装太多的常用软件,apk类似于ubuntu的apt-get,
## 用来安装一些常用软V件,其语法如下:apk add bash wget curl git make vim docker
## wget是linux下的ftp/http传输工具,没安装会报错“/bin/sh: wget: not found”,网上例子少安装wget
## ca-certificates证书服务,是安装glibc前置依赖
RUN apk --no-cache add ca-certificates wget \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& apk add glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk \
&& rm -rf /var/cache/apk/* glibc-2.29-r0.apk glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk
#7.配置环境变量
ENV JAVA_HOME=/xiaoye/jdk/jdk1.8.0_221
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH
#容器启动时需要执行的命令
#CMD ["java","-version"]
Dockerfile使用 alpine 基础镜像制作jdk运行环境
最新推荐文章于 2024-07-16 16:38:22 发布