英文:
Specifying JVM Options in docker-compose File
问题
version: '3.1'
services:
service:
image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
container_name: serviceApp
env_file: docker-compose.env
environment:
- JVM_OPTS=-XX:NativeMemoryTracking=summary
-XX:+StartAttachListener
-XX:+UseSerialGC
-Xss512k
-Dcom.sun.management.jmxremote.rmi.port=8088
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=8088
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
ports:
- 8088:8088
networks:
- services
working_dir: /opt/app
command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar"]
networks:
services:
external:
name: services
英文:
Currently I am trying to pass JVM options to my docker-compose.yml file. And this JVM_OPTS part in 'environment:' doesn't seem to be working. Is there another way to pass JVM options to docker-compose.yml file?
And also my DockerFile image is FROM openjdk:8-jre-alpine.
And my docker-compose.yml file is like this.
version: '3.1'
services:
service:
image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
container_name: serviceApp
env_file: docker-compose.env
environment:
- JVM_OPTS=-XX:NativeMemoryTracking=summary
-XX:+StartAttachListener
-XX:+UseSerialGC
-Xss512k
-Dcom.sun.management.jmxremote.rmi.port=8088
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=8088
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
ports:
- 8088:8088
networks:
- services
working_dir: /opt/app
command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar""]
networks:
services:
external:
name: services
And If you ask of these arguments, I am trying to connect VisualVM to a local docker container.
答案1
得分: 5
切换环境声明从序列样式到值映射样式,允许使用YAML多行字符串操作符'>'。它将合并所有行为一行。
version: '3.1'
services:
service:
image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
container_name: serviceApp
env_file: docker-compose.env
environment:
JVM_OPTS: >
-XX:NativeMemoryTracking=summary
-XX:+StartAttachListener
-XX:+UseSerialGC
-Xss512k
-Dcom.sun.management.jmxremote.rmi.port=8088
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=8088
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
ports:
- 8088:8088
networks:
- services
working_dir: /opt/app
command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar"]
networks:
services:
external:
name: services
(Note: The code portion is not translated as per your request.)
英文:
Switching the environment declaration from sequence style to value-map style allows to use the YAML multiline string operator '>'. It will merge all lines to a single line.
version: '3.1'
services:
service:
image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
container_name: serviceApp
env_file: docker-compose.env
environment:
JVM_OPTS: >
-XX:NativeMemoryTracking=summary
-XX:+StartAttachListener
-XX:+UseSerialGC
-Xss512k
-Dcom.sun.management.jmxremote.rmi.port=8088
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=8088
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
ports:
- 8088:8088
networks:
- services
working_dir: /opt/app
command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar""]
networks:
services:
external:
name: services
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论