基于干净的ubuntu或者debian构建java环境或者构建mvn环境

debian版本

版本名称版本号Docker镜像描述
bullseye11debian:bullseye、debian:bullseye-slim当前的稳定(stable)版
buster10debian:buster、debian:buster-slim当前的旧的稳定(oldstable)版
stretch9debian:stretch、debian:stretch-slim更旧的稳定(oldoldstable)版,现有长期支持
jessie8debian:jessie已存档版本,现有扩展长期支持
wheezy7debian:wheezy被淘汰的稳定版
squeeze6.0debian:squeeze被淘汰的稳定版
lenny5.0debian:lenny被淘汰的稳定版
etch4.0debian:etch被淘汰的稳定版
sarge3.1debian:sarge被淘汰的稳定版
woody3.0debian:woody被淘汰的稳定版
potato2.2debian:potato被淘汰的稳定版
slink2.1debian:slink被淘汰的稳定版
hamm2.0debian:hamm被淘汰的稳定版

Ubuntu版本

版本名称版本号Docker镜像
precise12.04ubuntu:12.04
quantal12.10ubuntu:12.10
trusty14.04ubuntu:14.04
utopic14.10ubuntu:14.10
vivid15.04ubuntu:15.04
wily15.10ubuntu:15.10
xenial16.04ubuntu:16.04
yakkety16.10ubuntu:16.10
bionic18.04ubuntu:18.04
cosmic18.10ubuntu:18.10
focal20.04ubuntu:20.04
groovy20.10ubuntu:20.10
jammy22.04ubuntu:22.04
kinetic22.10ubuntu:22.10
lunar23.04ubuntu:23.04

构建「构建环境」镜像

FROM ubuntu:22.10

ENV JAVA_HOME=/opt/jdk8u352-b08
ENV M2_HOME=/opt/apache-maven-3.8.6
ENV PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

ADD OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz /opt/
ADD apache-maven-3.8.6-bin.tar.gz /opt/

RUN \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic main restricted universe multiverse" > /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-security main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-proposed main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-security main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-proposed main restricted universe multiverse" >> /etc/apt/sources.list

COPY settings.xml /root/.m2/

如果基础镜像采用了Debian,则在执行apt-update时会出现如下的异常:

# apt-get update
Get:1 http://mirrors.cloud.tencent.com/ubuntu kinetic InRelease [267 kB]
Get:2 http://mirrors.cloud.tencent.com/ubuntu kinetic-security InRelease [109 kB]
Get:3 http://mirrors.cloud.tencent.com/ubuntu kinetic-updates InRelease [109 kB]
Err:1 http://mirrors.cloud.tencent.com/ubuntu kinetic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
Err:2 http://mirrors.cloud.tencent.com/ubuntu kinetic-security InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
Err:3 http://mirrors.cloud.tencent.com/ubuntu kinetic-updates InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
Get:4 http://mirrors.cloud.tencent.com/ubuntu kinetic-backports InRelease [99.9 kB]
Err:4 http://mirrors.cloud.tencent.com/ubuntu kinetic-backports InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
Get:5 http://mirrors.cloud.tencent.com/ubuntu kinetic-proposed InRelease [267 kB]
Err:5 http://mirrors.cloud.tencent.com/ubuntu kinetic-proposed InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
Reading package lists... Done
W: GPG error: http://mirrors.cloud.tencent.com/ubuntu kinetic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
E: The repository 'http://mirrors.cloud.tencent.com/ubuntu kinetic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.tencent.com/ubuntu kinetic-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
E: The repository 'http://mirrors.cloud.tencent.com/ubuntu kinetic-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.tencent.com/ubuntu kinetic-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
E: The repository 'http://mirrors.cloud.tencent.com/ubuntu kinetic-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.tencent.com/ubuntu kinetic-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
E: The repository 'http://mirrors.cloud.tencent.com/ubuntu kinetic-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.cloud.tencent.com/ubuntu kinetic-proposed InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
E: The repository 'http://mirrors.cloud.tencent.com/ubuntu kinetic-proposed InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

可以使用如下办法

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 871920D1991BC93C

如果有其他PUBKEY不可用,则采用同样的方法解决,注意apt-key需要使用旧的源安装好

构建「运行环境」镜像

FROM ubuntu:22.10

ENV JAVA_HOME=/opt/jdk8u352-b08
ENV M2_HOME=/opt/apache-maven-3.8.6
ENV PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

ADD OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz /opt/

RUN \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic main restricted universe multiverse" > /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-security main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb http://mirrors.cloud.tencent.com/ubuntu/ kinetic-proposed main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-security main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
  echo "deb-src http://mirrors.cloud.tencent.com/ubuntu/ kinetic-proposed main restricted universe multiverse" >> /etc/apt/sources.list

使用案例

FROM build-env:v1 as Builder

WORKDIR /work

COPY . /work/

RUN mvn -q clean package -DskipTests

FROM runtime-env:v1

WORKDIR /work

COPY --from=Builder /work/xxx.tgz /work

RUN tar xf xxx.tgz -C /work && \
    rm -fr /work/xxx.tgz

EXPOSE 8080

ENTRYPOINT bash /work/limiter/run.sh run com.to.path.XXXApplication pro

如此,可以构建一个相对干净的运行环境。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值