skip to Main Content

I’m using this Dockerfile configuration

FROM openjdk:17-alpine

ARG APP_HOME=/app

WORKDIR $APP_HOME

COPY ./target/ws-exec.jar ws.jar

ENV JAVA_OPTS="-Dspring.profiles.active=prod -Dspring.application.name=words"

ENTRYPOINT java $JAVA_OPTS -jar ./ws.jar $JAVA_ARGS

After deploying it to minikube, I see the only log:
Error: Unable to access jarfile /ws.jar.

I’ve tried to run docker run -it <image> with my image’s name, and it successfuly started with docker. Running docker exec -it <container> shew me that the jar is present in the right folder. I tried to make the jar executable adding a CMD or RUN layer into my Dockerfile, but nothing helped.
Where is my mistake, or what I don’t understand?

UPD here is my deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: revise-words-ws
  name: revise-words-ws
  namespace: default
spec:
  replicas: 1
  minReadySeconds: 45
  selector:
    matchLabels:
      app: revise-words-ws
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: revise-words-ws
    spec:
      containers:
        - image: maxrybalkin91/revise-words-ws:1.0
          imagePullPolicy: IfNotPresent
          name: revise-words-ws
          env:
            - name: VAULT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: words
                  key: vault_token
            - name: VAULT_HOST
              valueFrom:
                secretKeyRef:
                  name: words
                  key: vault_host
            - name: VAULT_PORT
              valueFrom:
                secretKeyRef:
                  name: words
                  key: vault_port
          ports:
            - name: liveness-port
              containerPort: 8089
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 300m
              memory: 512Mi
          readinessProbe:
            httpGet:
              path: /
              port: liveness-port
            failureThreshold: 5
            periodSeconds: 10
            initialDelaySeconds: 60
          livenessProbe:
            httpGet:
              path: /
              port: liveness-port
            failureThreshold: 5
            periodSeconds: 10
            initialDelaySeconds: 60
            terminationGracePeriodSeconds: 30
      restartPolicy: Always

2

Answers


  1. As ENTRYPOINT you specify Java to run ./ws.jar, assuming it would resolve from within work directory /app.
    At runtime you get the error message that /ws.jar is not accessible, which looks like an absolute path.

    When running your container with /bin/bash, please check out where your jar file exists and which mode it has. Then decide who is right and who is broken: Your docker file or your error message. Fix the broken one.

    Login or Signup to reply.
  2. If, as you say the jar file is in the right location (and I assume that is /app), how about using the absolute path for execution?

    ENTRYPOINT java $JAVA_OPTS -jar $APP_HOME/ws.jar $JAVA_ARGS
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search