0

This is the start.sh script i am using:

#!/bin/bash

touch app.log
HEAP_SIZE="-Xms1G -Xmx2G"
GC_ARGS="-XX:+UseG1GC -XX:+UseStringDeduplication -XX:+HeapDumpOnOutOfMemoryError"
ARGS="$HEAP_SIZE $GC_ARGS"
echo $ARGS
echo $PWD

nohup java $ARGS -jar app.jar > app.log 2>&1 &

chmod a+r app.log


and Dockerfile

FROM adoptopenjdk/openjdk11:latest
WORKDIR /app/app-1
COPY ./ ./

CMD ["./start.sh"]

When i replace the start.sh in CMD with java -jar app.jar then it starts the container but with start.sh it immediately exists and i don't see any error either and i checked start.sh has execute permissions so not able to figure out the issue, any help ?

After further debugging found issue is with & in shell script command, so container is getting started but it exits immediately, but still don't know the exact reason of why it is happening with &.

UPDATED - 29-Apr-2020 I am able to start the app inside container by removing nohup and & (at the end). But with stdout and stderr are redirected "> app.log 2> &1" then it does not show logs when i run "docker run -it ..." i.e. it is not redirecting logs docker container's stdout.

user10916892
  • 825
  • 12
  • 33

2 Answers2

1

Try removing nohup in the script.

Naveen Kulkarni
  • 633
  • 6
  • 16
  • well nohup is not a problem here, removing & works but not yet sure why. – user10916892 Apr 09 '20 at 12:44
  • 1
    There has to be an active process to keep the container alive, because of nohup and the & at the end the java process will go in background. Hence docker doesn't know which is an active process and assumes the container has finished its task and exits. – Naveen Kulkarni Apr 11 '20 at 05:01
0

Substitute the line #!/bin/bash for #!/bin/sh. As it seems, the Docker Image adoptopenjdk/openjdk11:latest comes with /bin/sh instead of /bin/bash.

Rômulo Pereira
  • 331
  • 4
  • 6