基礎鏡像為Ubuntu 20.04章贞,Ubuntu 的源存放在在 /etc/apt/ 目錄下的 sources.list 文件中;
默認更新源是國外服務器宪祥,在更新連接相關的服務器的時候进宝,可能出現無法鏈接的情況,導致系統(tǒng)的更新或者軟件的安裝無法正常完成院促。其實國內有很多的Ubuntu的鏡像源。比較知名的有阿里、網易上的Ubuntu數據源一疯。
改用國內阿里的軟件源,在本機創(chuàng)建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