Fork me on GitHub

制作基于 apline 的 jdk11 环境

制作基于 apline 的 jdk11 环境

没有搞定的方法:

https://blog.csdn.net/qq_43059674/article/details/103356158

https://juejin.cn/post/7082235890180816904

以上两种方法都试过了,没有成功。也不想深究原因了,主要是执行到 RUN 命令时报错:

Step 4/10 : ADD openjdk-11.0.2_linux-x64_bin.tar.gz .
 ---> e689709810fd
Step 5/10 : 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
 ---> Running in c95b21a59983
/bin/sh:  : not found
The command '/bin/sh -c echo http://mirrors.aliyun.com/alpine/v3.10/main/ > /etc/apk/repositories &&   echo http://mirrors.aliyun.com/alpine/v3.10/community/ >> /etc/apk/repositories' returned a non-zero code: 127

使用这里介绍的办法:https://www.coder.work/article/7507519

docker run -it alpine:3.11

# apk add openjdk11 安装 openjdk11的命令,类似于centos 的 yum install 

# java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-alpine-r0)
OpenJDK 64-Bit Server VM (build 11.0.5+10-alpine-r0, mixed mode)

先拉取镜像 alpine:3.11,并启动一个容器,进入该容器,安装 openjdk11,这里应该是可以通过将下载的jdk11相关tar.gz复制到容器中,然后配置好环境变量,目的是可以全局访问 JAVA_HOME 的bin 目录,最好配置以下的环境变量

ENV JAVA_HOME=/cpc_docker/jdk/jdk1.8.0_221
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$JAVA_HOME/bin:$PATH

将该容器提交为一个镜像

docker rename jovial_jepsen apline-openjdk11

docker commit -m '自己制作的apline-openjdk11奖项(描述信息)' -a '作者信息' apline-openjdk11 apline-openjdk11:1.0

将该镜像作为基础镜像打包新镜像的时候

# 设置基准镜像
FROM cumtsgw/alpine-openjdk11:v1.0 AS BUILD
# FROM 8feb2cdbcb55 AS BUILD
# 维护者
MAINTAINER nickel cumtsgw@163.com
# 将指定的文件或者目录复制到镜像的指定目录中
ADD . /server
WORKDIR /server

ENV dir="hello"

ENV rtsp="hello"

# 启动端口
EXPOSE 8080

# 容器运行后默认将要执行jar包的命令
ENTRYPOINT ["sh", "-c", "java -jar demo-0.0.1-SNAPSHOT.jar --rtsp=${rtsp} --dir=${dir}"]

FROM 后面的镜像,不能是本地镜像,起码是要从仓库下载,下载过一次之后,后面打包是否还要下载就不知道了。

如果考虑使用本地镜像作为基础镜像,而仓库里没有的时候,会报错:

root@aliyun demo]# docker buildx build -f ./Dockerfile.apline -t demo-apline:v1.0 --platform=linux/amd64 -o type=docker .
[+] Building 3.2s (4/4) FINISHED                                                                                                                    
 => [internal] load build definition from Dockerfile.apline                                                                                    0.0s
 => => transferring dockerfile: 478B                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                              0.0s
 => => transferring context: 2B                                                                                                                0.0s
 => ERROR [internal] load metadata for docker.io/library/alpine-openjdk11:v1.0                                                                 2.4s
 => [auth] library/alpine-openjdk11:pull token for registry-1.docker.io                                                                        0.0s
------
 > [internal] load metadata for docker.io/library/alpine-openjdk11:v1.0:
------
Dockerfile.apline:2
--------------------
   1 |     # 设置基准镜像
   2 | >>> FROM alpine-openjdk11:v1.0 AS BUILD
   3 |     # FROM 8feb2cdbcb55 AS BUILD
   4 |     # 维护者
--------------------
error: failed to solve: alpine-openjdk11:v1.0: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

在 x86的机器上运行 arm 环境

注册qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static:register --reset

启动对应架构的docker镜像
docker run -itd --name armv8 multiarch/alpine:aarch64-edge /bin/sh

FROM alpine:3.15.4

apk add openjdk11 --repository=http://mirrors.aliyun.com/alpine/edge/community/
apk add ffmpeg --repository=http://mirrors.aliyun.com/alpine/edge/community/

apk add ffmpeg --repository=http://mirrors.aliyun.com/alpine/edge/community/

docker manifest create cumtsgw/alpine-jdk11:2022-04-24 cumtsgw/alpine-jdk11:amd cumtsgw/alpine-jdk11:arm
docker manifest push cumtsgw/alpine-jdk11:2022-04-24
docker manifest rm cumtsgw/alpine-jdk11:2022-04-24

docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d

ls -al /proc/sys/fs/binfmt_misc/

posted @ 2023-09-23 10:30  Catalinas  阅读(454)  评论(0编辑  收藏  举报