Here is a simple shell script that checks to see if docker is installed. If docker is installed it then filters to see if a container with a certain name is also running and if it is not it will trigger the run command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#!/bin/sh clear if [ "$(docker --version)" ] then if [ "$(docker ps --filter 'name=container_name')" ] then echo "---- CONTAINER ALREADY EXISITS ----" NODE_ENV=local sails lift else docker run --name container_name -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_USER=postgres -e POSTGRES_DB=mydatabase -p 9999:5432 -d postgres:latest echo "---- CONTAINER CREATED RUNNING APPLICATION ----" NODE_ENV=local sails lift fi else echo "---- DOCKER IS NOT INSTALLED ----" fi |