构建Ubuntu+GCC+jdk8的Docker镜像

基础镜像为Ubuntu 20.04,Ubuntu 的源存放在在 /etc/apt/ 目录下的 sources.list 文件中;
默认更新源是国外服务器,在更新连接相关的服务器的时候,可能出现无法链接的情况,导致系统的更新或者软件的安装无法正常完成。其实国内有很多的Ubuntu的镜像源。比较知名的有阿里、网易上的Ubuntu数据源。
改用国内阿里的软件源,在本机创建sources.list文件,构建镜像时,将此文件COPY到镜像中。

sources.list文件内容如下:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
Dockerfile文件内容如下:
FROM ubuntu:20.04
 
COPY sources.list /etc/apt/
RUN apt-get update; exit 0
RUN apt-get upgrade; exit 0
 
# 添加中文支持
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get install -y locales
RUN locale-gen zh_CN.UTF-8 && \
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
RUN locale-gen zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
ENV LANGUAGE zh_CN:zh
ENV LC_ALL zh_CN.UTF-8
ENV LC_ALL="C.UTF-8" LANG="C.UTF-8"
 
# 安装gcc
RUN apt update; exit 0
RUN apt install -y build-essential
 
# 安装openjdk
RUN set -eux; \
    apt-get install -y openjdk-8-jdk; \
    apt-get clean; \
    rm -rf /var/lib/apt/lists/*; \
    rm -rf /var/cache/oracle-jdk8-installer
     
RUN apt-get install -y ca-certificates-java; \
    apt-get clean; \
    update-ca-certificates -f; \
    rm -rf /var/lib/apt/lists/*; \
    rm -rf /var/cache/oracle-jdk8-installer
     
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
 
RUN export JAVA_HOME
 
RUN java -version
Dockerfile所在目录下构建镜像:
docker build -t cherishpf/ubuntu20-gcc-java:v1 .
拉取该镜像(总大小897M):
docker pull cherishpf/ubuntu20-gcc-java:v1

你可能感兴趣的:(构建Ubuntu+GCC+jdk8的Docker镜像)