I have a very simple Docker container which runs a bash script:
# syntax=docker/dockerfile:1.4
FROM alpine:3
WORKDIR /app
RUN apk add --no-cache
curl bash sed uuidgen
COPY demo.sh /app/demo.sh
RUN chmod +x /app/*.sh
CMD ["bash", "/app/demo.sh"]
#!/bin/bash
echo "Test 123.."
sleep 5m
echo "After sleep"
When running the container with docker run <image>
the container cannot be stopped with docker stop <name>
, it can only be killed.
I tried searching but everything with "bash" and "docker" leads me to managing docker on host with shell scripts.
2
Answers
sleep
is an example of an uninterruptible command; your shell never receives theSIGTERM
untilsleep
completes.A common workaround is to run
sleep
in the background, and immediately wait on it, so that it’s the shell built-inwait
that’s running when the signal arrives, andwait
is interruptible.Can you try to add this before the sleep statement ?
Or do
docker stop -t 5 container
for example.