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
-Xmn1536m
-XX:SurvivorRatio=1
-XX:MetaspaceSize=256m
-XX:MaxMetaspaceSize=256m
-XX:ParallelGCThreads=4
-XX:+PrintGCDetails
-XX:+PrintTenuringDistribution
-XX:+PrintGCTimeStamps
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/
-Xloggc:/logs/gc.log
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=5
-XX:+DisableExplicitGC
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:+CMSParallelRemarkEnabled
-XX:+CMSClassUnloadingEnabled
-XX:LargePageSizeInBytes=128M
-XX:+UseFastAccessorMethods
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=80
-XX:SoftRefLRUPolicyMSPerMB=0
-XX:+PrintClassHistogram
-XX:+PrintHeapAtGC
-XX:+UnlockDiagnosticVMOptions
-XX:+UnlockExperimentalVMOptions
-XX:+PrintFlagsFinal
-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=-server -Xmx4000M -Xms4000M -Xmn600M -Xss256K -XX:+DisableExplicitGC -XX:SurvivorRatio=1 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+CMSClassUnloadingEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintClassHistogram -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -Xloggc:/logs/gc.log
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}}'