'Issuing a command within a docker container to kill it
I'd like to use a bash script within a container to check if the service is running. I will call this script from docker-compose using the Healthcheck function, the script from within the container will be run every few minutes. If the command in the script receives an error response from the service, it will issue a command from within the container to kill itself. Is this possible? I need to destroy the container, not just the services running inside.
#!/bin/bash
$container_service_status="service status bash command"
if [[ "$container_service_status" == *"service not responding"* ]] ; then
Command to kill the container
#I tried kill 1, it didn't stop the container
fi
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|