Skip to content

Instantly share code, notes, and snippets.

@JackLiar
JackLiar / run_container.sh
Created July 16, 2019 14:10
If a target name contianer does not exist or is exited, create it or restart it.
# /bin/bash
# modified from https://stackoverflow.com/questions/38576337/how-to-execute-a-bash-command-only-if-a-docker-container-with-a-given-name-does
image_name="somebody/some_image"
container_name="name_of_container"
if [ ! "$(docker ps -q -f name=$container_name)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$container_name)" ]; then
# if container is exited, restart it, and run in interaction mode