gpt4 book ai didi

docker - 如何在 Docker 容器中增加 Corda 节点的内存限制

转载 作者:行者123 更新时间:2023-12-02 18:18:03 27 4
gpt4 key购买 nike

部署 Corda 节点时,JVM XmX参数用于增加节点的内存限制,但当通过容器部署时,官方 Corda 镜像会抛出警告

WARNING: the use of the -Xmx flag is not recommended within docker containers. Use the --memory option passed to the container to limit heap size



https://github.com/corda/corda/blob/release/os/4.4/docker/src/bash/run-corda.sh#L4

为容器设置内存限制是不够的,因为节点本身因容器内的 OOM 异常而崩溃。

使用开源时,您可以绕过 XmX参数通过设置节点配置如下:
custom = {
jvmArgs: [ "-Xmx1G", "-XX:+UseG1GC" ]
}

有没有办法通过 dockerfile 或 docker compose 而不是配置来设置 Corda 节点内存限制?

最佳答案

您可以使用 docker-compose 来传递 JVM_ARGS作为容器的环境变量。

 partya:
image: corda/corda-zulu-java1.8-4.4
container_name: partya
ports:
- "10006:10201"
environment:
- JVM_ARGS=-Xmx6g -Xms2g -XX:+UseG1GC
volumes:
- ./Network/PartyA/node.conf:/etc/corda/node.conf
- ./Network/PartyA/certificates:/opt/corda/certificates
- ./Network/PartyA/persistence:/opt/corda/persistence
- ./Network/PartyA/logs:/opt/corda/logs
- ./Network/Shared/cordapps:/opt/corda/cordapps
- ./Network/Shared/node-infos:/opt/corda/additional-node-infos
- ./Network/Shared/network-parameters:/opt/corda/network-parameters

但这不会帮助您摆脱警告,因为脚本仍将用于运行节点。

如果你真的想摆脱警告,你可以使用 command覆盖默认运行脚本。
partya:
image: corda/corda-zulu-java1.8-4.4
container_name: partya
ports:
- "10006:10201"
command: java -Dcapsule.jvm.args=-Xmx6g -Xms2g -XX:+UseG1GC -jar /opt/corda/bin/corda.jar --base-directory /opt/corda --config-file /etc/corda/node.conf
volumes:
- ./Network/PartyA/node.conf:/etc/corda/node.conf
- ./Network/PartyA/certificates:/opt/corda/certificates
- ./Network/PartyA/persistence:/opt/corda/persistence
- ./Network/PartyA/logs:/opt/corda/logs
- ./Network/Shared/cordapps:/opt/corda/cordapps
- ./Network/Shared/node-infos:/opt/corda/additional-node-infos
- ./Network/Shared/network-parameters:/opt/corda/network-parameters

关于docker - 如何在 Docker 容器中增加 Corda 节点的内存限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61913688/

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