gpt4 book ai didi

java - 为什么 Docker 中的 Gerrit 找不到 JAVA_HOME?

转载 作者:行者123 更新时间:2023-12-01 16:13:58 28 4
gpt4 key购买 nike

我已将 Gerrit 安装到 Docker 容器中,以及依赖项 httpd 和 postgres。 docker-compose.yml 文件如下所示:

version: '3.1'

services:
gerrit:
image: gerritcodereview/gerrit
environment:
- CANONICAL_WEB_URL=http://ooi-pmo-prd02.whoi.edu:8080/
volumes:
- ./gerrit/etc:/var/gerrit/etc/
- ./gerrit/git:/var/gerrit/git/
- ./gerrit/index:/var/gerrit/index/
- ./gerrit/cache:/var/gerrit/cache/
ports:
- "29418:29418"
links:
- postgres
depends_on:
- postgres

apache:
image: httpd
volumes:
- ./httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
- ./httpd/.htpasswd:/usr/local/apache2/conf/.htpasswd
ports:
- "8080:80"

postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=gerrit2
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=reviewdb
volumes:
- ./postgres/:/var/lib/postgresql/data

Apache 和 Postgres 启动没有问题,但 Java 由于无法找到有效的 JDK 或 JRE 而无法启动,就好像它在我的 gerrit.config 文件中没有看到 JAVA_HOME 环境变量或 javaHome 选项一样(如下):

[gerrit]
basePath = git
canonicalWebUrl = http://ooi-pmo-prd02.whoi.edu:8080/
serverId = 85d6f505-5412-4eef-9f26-e844e9efd258
[database]
type = postgresql
hostname = localhost
database = reviewdb
username = gerrit2
[index]
type = LUCENE
[auth]
type = HTTP
logoutUrl = http://aa:aa@ooi-pmo-prd02.whoi.edu:8080/logout
httpHeader =
[sendemail]
smtpServer = localhost
smtpUser = gerrit2
[container]
user = root
javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
[httpd]
listenUrl = http://ooi-pmo-prd02.whoi.edu:8080/
[cache]
directory = cache
[sshd]
listenAddress = *:29418
[user]
name = gerrit2
email = pmena@whoi.edu

启动后,gerrit 立即失败并出现以下错误:

pmena@ooi-pmo-prd02=> docker logs gerrit_gerrit_1
Running Gerrit ...
Cannot find a JRE or JDK. Please ensure that the JAVA_HOME environment
variable or container.javaHome in /var/gerrit/etc/gerrit.config is
set to a valid >=1.8 JRE location

尽管事实上 JAVA_HOME 与上面指定的 JRE 匹配 - 并且它是有效的:

pmena@ooi-pmo-prd02=> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
pmena@ooi-pmo-prd02=> ls -l /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
total 4
drwxr-xr-x. 2 root root 172 Apr 9 14:04 bin
drwxr-xr-x. 9 root root 4096 Apr 9 14:02 lib
pmena@ooi-pmo-prd02=> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

当 Java 在 Docker 容器中运行时,是否有一些技巧可以让 Gerrit“看到”Java?

最佳答案

docker-compose 与图片:gerritcodereview/gerrit:3.1.2

我 exec -it 到 gerrit 获取 java_home

bash-4.2$ ls -hl  /usr/lib/jvm/
total 0
drwxr-xr-x. 3 root root 17 Dec 14 2019 java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
lrwxrwxrwx. 1 root root 21 Dec 14 2019 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Dec 14 2019 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx. 1 root root 35 Dec 14 2019 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx. 1 root root 51 Dec 14 2019 jre-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64 -> java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
lrwxrwxrwx. 1 root root 29 Dec 14 2019 jre-openjdk -> /etc/alternatives/jre_openjdk

这样你就可以在gerrit.config中设置容器

[container]
user = gerrit
javaOptions = -Dfile.encoding=UTF-8
javaHome = "/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre"

关于java - 为什么 Docker 中的 Gerrit 找不到 JAVA_HOME?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62452085/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com