user10916892
user10916892

Reputation: 997

Not able to start docker container with shell script

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.

Upvotes: 0

Views: 984

Answers (2)

Rômulo Pereira
Rômulo Pereira

Reputation: 341

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.

Upvotes: 0

Naveen Kulkarni
Naveen Kulkarni

Reputation: 803

Try removing nohup in the script.

Upvotes: 1

Related Questions