4

实例

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


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...