1

In my Dockerfile, I start a process using CMD:

# Start MyProcess
CMD ./my_process.sh >> /log/myprocess.log

my_process.sh may exit 0 according to some conditions inside that script. Is there a way to safely stop the container from running/starting? right now, it keeps restarting indefinitely

1 Answer 1

2

You can try leveraging restart policies, add below argument during docker run -

docker run --restart on-failure .....

--restart on-failure

Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.

Ref - https://docs.docker.com/engine/reference/commandline/run/

Sign up to request clarification or add additional context in comments.

2 Comments

is it possible to specify two policies? unless-stopped and on-failure
I don't think you can add two policies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.