记一次docker打包部署历程

embedded/2024/9/23 6:14:02/

1、docker容器的系统信息

$ uname -a
Linux runner-nymzs2tf-project-194-concurrent-0tj8jr 5.4.191-1.el7.elrepo.x86_64 #1 SMP Tue Apr 26 12:14:16 EDT 2022 x86_64 Linux
$ cat /etc/os-release
NAME="**Alpine Linux**"
ID=alpine
VERSION_ID=3.9.4
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

2、docker容器所在linux服务器信息

Containers: 183Running: 105Paused: 0Stopped: 78
Images: 21187
Server Version: 20.10.15
Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueuserxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc version: v1.1.1-0-g52de29d
init version: de40ad0
Security Options:seccompProfile: default
Kernel Version: 5.4.191-1.el7.elrepo.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 96
Total Memory: 251.4GiB
Name: pro-worker-2
ID: FTIN:HRYA:B4GQ:KOPL:E7K3:SNOY:CET4:ESZ3:H26S:REJN:EM6W:PPCH
Docker Root Dir: /data/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:0.0.0.0/0127.0.0.0/8
Live Restore Enabled: false

3、gitlab runner docker容器中已有环境 (gitlab runner使用docker容器启动)

jdk8
docker
maven

4、需求是在.gitlab-ci.yml中实现对 jdk17代码打包,然后使用docker发布到本地镜像仓库 。

5、限制:不能登录gitlab runner所在服务器,只能使用.gitlab-ci.yml 去改变运行环境

下面是我的思路:(路程一言难尽)

方案一:

1、直接替换容器jdk不就可以了吗?easy啊
2、我使用wget命令下载 wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
3、然后使用export 改变环境变量。

报错:$ java -version
/bin/bash: line 147: /jdk17/jdk-17.0.11/bin/java: No such file or directory
我还以为是java home没有配置正确,反复检查发现没有配置错误。**这里实际上应该可以得出结论:这个jdk无法在当前系统运行。**然后我在本地用同样的方式,发现可以运行,换到服务器也可以运行。我确定jdk文件是没问题的,一定是docker容器环境不支持这个版本jdk,但当时没有深追原因,因为我还有第二种办法。

方案二:既然gitlab runner是通过docker容器启动,那么直接修改.gitlab-ci.yml文件不就可以了吗,我真是个大聪明
1、我在容器第一行添加image

image: isc/jdk17-docker:latest

2、本地将jdk17 maven docker 安装到jdk17-docker:latest镜像中。
3、做好后启动 ci,发现容器启动报错,提示如下。主要是docker容器内部启动必须配置 privileged=true

time="2024-09-21T15:35:33.853658345Z" level=info msg="parsed scheme: \"unix\"" module=grpc
time="2024-09-21T15:35:33.854087855Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
time="2024-09-21T15:35:33.854184776Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}" module=grpc
time="2024-09-21T15:35:33.854197034Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2024-09-21T15:35:33.857295871Z" level=info msg="parsed scheme: \"unix\"" module=grpc
time="2024-09-21T15:35:33.857311351Z" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
time="2024-09-21T15:35:33.857324946Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}" module=grpc
time="2024-09-21T15:35:33.857331518Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2024-09-21T15:35:33.863311092Z" level=error msg="failed to mount overlay: operation not permitted" storage-driver=overlay2
time="2024-09-21T15:35:33.864648534Z" level=error msg="exec: \"fuse-overlayfs\": executable file not found in $PATH" storage-driver=fuse-overlayfs
time="2024-09-21T15:35:33.865747803Z" level=error msg="AUFS was not found in /proc/filesystems" storage-driver=aufs
time="2024-09-21T15:35:33.867654453Z" level=error msg="failed to mount overlay: operation not permitted" storage-driver=overlay
time="2024-09-21T15:35:33.903746269Z" level=info msg="Loading containers: start."
time="2024-09-21T15:35:33.913066400Z" level=warning msg="Running iptables --wait -t nat -L -n failed with message: `iptables v1.8.6 (legacy): can't initialize iptables table `nat': Permission denied (you must be root)\nPerhaps iptables or your kernel needs to be upgraded.`, error: exit status 3"
time="2024-09-21T15:35:33.948514176Z" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=moby
time="2024-09-21T15:35:33.949115951Z" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
time="2024-09-21T15:35:33.950075353Z" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.8.6 (legacy): can't initialize iptables table `nat': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.

4、但是privileged=true是docker 容器特有命令,在gitlab-ci.yml文件是无法使用的。所以到最后还得研究为什么docker容器不支持jdk17

方案三:
1、怀疑是docker容器的硬件不支持
输出docker容器内核,指令架构。但是我下载的jdk是x64版本的

Linux runner-nymzs2tf-project-194-concurrent-0tj8jr 5.4.191-1.el7.elrepo.x86_64 #1 SMP Tue Apr 26 12:14:16 EDT 2022 x86_64 Linux

2、怀疑是操作系统的问题

$ cat /etc/os-release
NAME="**Alpine Linux**"
ID=alpine
VERSION_ID=3.9.4
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

3、由于Alpine完全没有听过,google了一下,alpine和其他linux系统还真不一样,主要区别是

Alpine 使用了 musl libc 作为标准 C 库,而不是更常见的 glibc

由此我怀疑就是这个原因导致普通jdk17无法运行。然后我使用apk(alpine自带软件包)安装jdk,更换镜像源后也还是无法安装,貌似使用apk安装无法找到符合alpine的jdk版本。然后我从Amazon Corretto 找到合适的jdk版本。


http://www.ppmy.cn/embedded/115447.html

相关文章

Java音视频文件解析工具

文章目录 一 jave-all-deps二 具体用法2.1 添加依赖2.2 视频转音频2.3 视频格式转换2.4 获取视频时长 三 总结 小伙伴们知道&#xff0c;松哥平时录了蛮多视频课程&#xff0c;视频录完以后&#xff0c;就想整理一个视频文档出来&#xff0c;在整理视频文档的时候&#xff0c;就…

Maven-四、继承

Maven进阶 文章目录 Maven进阶前言继承设置继承依赖管理总结 前言 一个项目中的不同模块可能引用的是同一个依赖&#xff0c;在这种情况下&#xff0c;单独在某个模块内引用太麻烦&#xff0c;于是maven使用继承的思想&#xff0c;在父模块中配置依赖包&#xff0c;其他需要这…

数据结构篇--顺序查找【详解】

概念章 查找就是在数据集合中寻找某种条件的数据元素的过程。 查找表是指用于查找同一类型的数据元素集合。 找到了满足条件的数据元素&#xff0c;就是查找成功&#xff0c;否则就是称为查找失败。 关键字是指数据元素的某个数据项的值&#xff0c;可用于标识或者记录&…

【IEEE 独立出版,快速EI检索】第四届人工智能、虚拟现实与可视化国际学术会议(AIVRV 2024)

第四届人工智能、虚拟现实与可视化国际学术会议&#xff08;AIVRV 2024&#xff09; 2024 4th International Conference on Artificial Intelligence, Virtual Reality and Visualization 官方信息 会议官网&#xff1a;www.aivrv.org 2024 4th International Conference on…

PHP 数组排序类型介绍

在PHP中&#xff0c;数组排序是一项常见且重要的操作&#xff0c;它允许开发者根据一定的规则对数组中的元素进行排序。PHP提供了多种数组排序函数&#xff0c;以适应不同的排序需求。这些函数包括基本的升序和降序排序&#xff0c;以及基于特定键值、自定义排序逻辑等的复杂排…

C++从入门到起飞之——多态 全方位剖析!

&#x1f308;个人主页&#xff1a;秋风起&#xff0c;再归来~&#x1f525;系列专栏&#xff1a;C从入门到起飞 &#x1f516;克心守己&#xff0c;律己则安 目录 1. 多态的概念 2. 多态的定义及实现 2.1 多态的构成条件 2.1.1 实现多态还有两个必须重要条件&…

学习篇 | 5步安装 npm node(homebrew 简洁版)

1. 操作步骤 1.1 安装 homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"1.2 安装 node # 安装最新版 brew install node # 安装指定版本&#xff0c;如18 brew install node181.3 安装 nvm&#xff08…

出厂非澎湃OS手机解BL锁

脚本作者&#xff1a;酷安mlgmxyysd 脚本项目链接&#xff1a;https://github.com/MlgmXyysd/Xiaomi-HyperOS-BootLoader-Bypass/ 参考 B站作者&#xff1a;蓝空穹 https://www.bilibili.com/read/cv33210124/ 其他参考&#xff1a;云墨清风、水墨青竹、Magisk中文网 决定解BL…