Add a check at the top of your script entry point
Docker really needs to implement this as a new feature, but there is another option for a workaround for situations in which you have an entry point that ends after success or failure, which can make debugging difficult.
If you don't have a script entry point yet, create one that executes any commands necessary for your container. Then at the top of this file add these lines to entrypoint.sh :
# Run once, hold otherwise if [ -f "already_ran" ]; then echo "Already ran the Entrypoint once. Holding indefinitely for debugging." cat fi touch already_ran
To ensure that cat contains a connection, you may need to provide TTY. I run the container with my script entry point as follows:
docker run -t --entrypoint entrypoint.sh image_name
This will cause the script to be run once, creating a file that indicates that it is already running (in the container’s virtual file system). Then you can restart the container to perform debugging:
docker start container_name
When the container is already_ran , the already_ran file will be found, as a result of which the script entry point will be closed with cat (which simply waits forever for input, which never arrives, but keeps the container in an active state). Then you can debug the bash session:
docker exec -i container_name bash
While the container is running, you can also remove already_ran and manually execute the entrypoint.sh script to restart it if you need to debug this path.
Ethan T Mar 03 '17 at 23:20 2017-03-03 23:20
source share