I'm writing a very simple bash script to quickly check that my container still builds and starts correctly and that the app inside responds to requests.
Sometimes docker run
fails, e.g. because the port I'm trying to bind the container to is already allocated. But when this happens docker run
's exit code is still 0 so I can't use the exit code. How can I check programmatically that the container got started correctly?
The solutions I'm considering are:
- parse the output for errors
docker ps
to see if the container is running
but these both seem a little overkill and ugly. Am I missing a better way to check whether docker run
succeeded?
docker run
will return a non-zero return code on failure as you indicate then all you can do is parse the output (which might be complicated or fragile) or use another command (i.e. yourps
suggestion) to check the result of the first command. You might want to consider filing a ticket with docker to see if they can fix the return code fromrun
also.docker run -d -p 9010:9010 busybox true ; echo $?