dockerfile指定jvm参数

实例

FROM java:8
VOLUME /tmp
ADD app.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 9001
ENV JAVA_OPTS="\
-server \
-Xmx4g \
-Xms4g \
-Xmn2g \
-XX:SurvivorRatio=8 \
-XX:MetaspaceSize=256m \
-XX:MaxMetaspaceSize=512m \
-XX:+UseParallelGC \
-XX:ParallelGCThreads=4 \
-XX:+UseParallelOldGC \
-XX:+UseAdaptiveSizePolicy \
-XX:+PrintGCDetails \
-XX:+PrintTenuringDistribution \
-XX:+PrintGCTimeStamps \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=/ \
-Xloggc:/gc.log \
-XX:+UseGCLogFileRotation \
-XX:NumberOfGCLogFiles=5 \
-XX:GCLogFileSize=10M"
ENTRYPOINT java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar

不过这种方式在dockerfile写死了不灵活,不是很推荐,特别是要区分env的应用来说。

docker run指定

docker run --rm -e JAVA_OPTS='-Xmx1g' tomcat

docker-compose方式指定

environment:
  - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=1024m

k8s指定

apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    app: jenkins
    role: master
    version: v1
  name: jenkins-master
  namespace: jenkins
spec:
  replicas: 1
  selector:
    app: jenkins
    role: master
    version: v1
  template:
    metadata:
      labels:
        app: jenkins
        role: master
        version: v1
    spec:
      containers:
      - env:
        - name: JENKINS_OPTS
          value: --prefix=
        - name: JAVA_OPTS
          value: -Djava.awt.headless=true -Xmx200m -Dcom.sun.management.jmxremote=
            -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false
            -Dcom.sun.management.jmxremote.authenticate=false
        image: jenkins:2.7.2
        name: jenkins
        ports:
        - containerPort: 8080
          name: web
        - containerPort: 50000
          name: leader
        resources:
          limits:
            cpu: 1000m
            memory: 800Mi
          requests:
            cpu: 100m
            memory: 400Mi
        volumeMounts:
        - mountPath: /var/jenkins_home
          name: jenkins-master
      nodeSelector:
        worker: "true"
      volumes:
      - name: jenkins-master
        nfs:
          path: /data/jenkins-master
          server: '{{nfs_server}}'

doc

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值