在docker-compose文件中指定JVM选项。

huangapple go评论95阅读模式
英文:

Specifying JVM Options in docker-compose File

问题

  1. version: '3.1'
  2. services:
  3. service:
  4. image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
  5. container_name: serviceApp
  6. env_file: docker-compose.env
  7. environment:
  8. - JVM_OPTS=-XX:NativeMemoryTracking=summary
  9. -XX:+StartAttachListener
  10. -XX:+UseSerialGC
  11. -Xss512k
  12. -Dcom.sun.management.jmxremote.rmi.port=8088
  13. -Dcom.sun.management.jmxremote=true
  14. -Dcom.sun.management.jmxremote.port=8088
  15. -Dcom.sun.management.jmxremote.ssl=false
  16. -Dcom.sun.management.jmxremote.authenticate=false
  17. -Dcom.sun.management.jmxremote.local.only=false
  18. -Djava.rmi.server.hostname=localhost
  19. ports:
  20. - 8088:8088
  21. networks:
  22. - services
  23. working_dir: /opt/app
  24. command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar"]
  25. networks:
  26. services:
  27. external:
  28. 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.

  1. version: '3.1'
  2. services:
  3. service:
  4. image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
  5. container_name: serviceApp
  6. env_file: docker-compose.env
  7. environment:
  8. - JVM_OPTS=-XX:NativeMemoryTracking=summary
  9. -XX:+StartAttachListener
  10. -XX:+UseSerialGC
  11. -Xss512k
  12. -Dcom.sun.management.jmxremote.rmi.port=8088
  13. -Dcom.sun.management.jmxremote=true
  14. -Dcom.sun.management.jmxremote.port=8088
  15. -Dcom.sun.management.jmxremote.ssl=false
  16. -Dcom.sun.management.jmxremote.authenticate=false
  17. -Dcom.sun.management.jmxremote.local.only=false
  18. -Djava.rmi.server.hostname=localhost
  19. ports:
  20. - 8088:8088
  21. networks:
  22. - services
  23. working_dir: /opt/app
  24. command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar""]
  25. networks:
  26. services:
  27. external:
  28. name: services

And If you ask of these arguments, I am trying to connect VisualVM to a local docker container.

答案1

得分: 5

切换环境声明从序列样式到值映射样式,允许使用YAML多行字符串操作符'>'。它将合并所有行为一行。

  1. version: '3.1'
  2. services:
  3. service:
  4. image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
  5. container_name: serviceApp
  6. env_file: docker-compose.env
  7. environment:
  8. JVM_OPTS: >
  9. -XX:NativeMemoryTracking=summary
  10. -XX:+StartAttachListener
  11. -XX:+UseSerialGC
  12. -Xss512k
  13. -Dcom.sun.management.jmxremote.rmi.port=8088
  14. -Dcom.sun.management.jmxremote=true
  15. -Dcom.sun.management.jmxremote.port=8088
  16. -Dcom.sun.management.jmxremote.ssl=false
  17. -Dcom.sun.management.jmxremote.authenticate=false
  18. -Dcom.sun.management.jmxremote.local.only=false
  19. -Djava.rmi.server.hostname=localhost
  20. ports:
  21. - 8088:8088
  22. networks:
  23. - services
  24. working_dir: /opt/app
  25. command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar"]
  26. networks:
  27. services:
  28. external:
  29. 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.

  1. version: '3.1'
  2. services:
  3. service:
  4. image: registry.gitlab.com/project/service/${BRANCH}:${TAG}
  5. container_name: serviceApp
  6. env_file: docker-compose.env
  7. environment:
  8. JVM_OPTS: >
  9. -XX:NativeMemoryTracking=summary
  10. -XX:+StartAttachListener
  11. -XX:+UseSerialGC
  12. -Xss512k
  13. -Dcom.sun.management.jmxremote.rmi.port=8088
  14. -Dcom.sun.management.jmxremote=true
  15. -Dcom.sun.management.jmxremote.port=8088
  16. -Dcom.sun.management.jmxremote.ssl=false
  17. -Dcom.sun.management.jmxremote.authenticate=false
  18. -Dcom.sun.management.jmxremote.local.only=false
  19. -Djava.rmi.server.hostname=localhost
  20. ports:
  21. - 8088:8088
  22. networks:
  23. - services
  24. working_dir: /opt/app
  25. command: ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/service.jar""]
  26. networks:
  27. services:
  28. external:
  29. name: services

huangapple
  • 本文由 发表于 2020年4月6日 02:41:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/61047654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定