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

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

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

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:

确定