Created
May 6, 2026 06:29
-
-
Save JaiminPatel345/ada42f14683a0278eb8bdc40bc0b605c to your computer and use it in GitHub Desktop.
Download usefull docker containers like Postgres, redis, PgAdmin, Mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Colors for output | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| RED='\033[0;31m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color | |
| echo -e "${BLUE}=== Docker Services Starter ===${NC}\n" | |
| # Collect user preferences first | |
| echo -e "${BLUE}Please select which services to run:${NC}\n" | |
| read -p "Do you want to run MongoDB? (yes/no): " run_mongodb | |
| read -p "Do you want to run Redis? (yes/no): " run_redis | |
| read -p "Do you want to run PostgreSQL? (yes/no): " run_postgresql | |
| read -p "Do you want to run pgAdmin4? (yes/no): " run_pgadmin | |
| echo -e "\n${BLUE}Starting selected services...${NC}\n" | |
| # Function to check yes/no response | |
| is_yes() { | |
| case $1 in | |
| [Yy]* | [Yy][Ee][Ss]* ) return 0;; | |
| * ) return 1;; | |
| esac | |
| } | |
| # Function to start or create container | |
| start_or_create() { | |
| local container_name=$1 | |
| local run_command=$2 | |
| # Check if container exists | |
| if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then | |
| # Container exists, check if it's running | |
| if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then | |
| echo -e "${YELLOW}${container_name} is already running${NC}" | |
| else | |
| echo -e "${GREEN}Starting existing ${container_name}...${NC}" | |
| docker start ${container_name} | |
| echo -e "${GREEN}${container_name} started${NC}" | |
| fi | |
| else | |
| # Container doesn't exist, create it | |
| echo -e "${GREEN}Creating and starting ${container_name}...${NC}" | |
| eval $run_command | |
| echo -e "${GREEN}${container_name} created and started${NC}" | |
| fi | |
| } | |
| # MongoDB | |
| if is_yes "$run_mongodb"; then | |
| start_or_create "mongodb" "docker run -d \ | |
| --name mongodb \ | |
| -p 27017:27017 \ | |
| -e MONGO_INITDB_ROOT_USERNAME=admin \ | |
| -e MONGO_INITDB_ROOT_PASSWORD=root123 \ | |
| -v mongodb_data:/data/db \ | |
| mongo:latest" | |
| echo -e "Port: 27017, Username: admin, Password: root123\n" | |
| else | |
| echo -e "${RED}Skipping MongoDB${NC}\n" | |
| fi | |
| # Redis | |
| if is_yes "$run_redis"; then | |
| start_or_create "redis" "docker run -d \ | |
| --name redis \ | |
| -p 6379:6379 \ | |
| -v redis_data:/data \ | |
| redis:latest" | |
| echo -e "Port: 6379\n" | |
| else | |
| echo -e "${RED}Skipping Redis${NC}\n" | |
| fi | |
| # PostgreSQL | |
| if is_yes "$run_postgresql"; then | |
| start_or_create "postgresql" "docker run -d \ | |
| --name postgresql \ | |
| -p 5432:5432 \ | |
| -e POSTGRES_USER=postgres \ | |
| -e POSTGRES_PASSWORD=root123 \ | |
| -e POSTGRES_DB=mydb \ | |
| -v postgres_data:/var/lib/postgresql \ | |
| postgres:latest" | |
| echo -e "Port: 5432, Username: postgres, Password: root123, Database: mydb\n" | |
| else | |
| echo -e "${RED}Skipping PostgreSQL${NC}\n" | |
| fi | |
| # pgAdmin4 | |
| if is_yes "$run_pgadmin"; then | |
| start_or_create "pgadmin4" "docker run -d \ | |
| --name pgadmin4 \ | |
| -p 5050:80 \ | |
| -e PGADMIN_DEFAULT_EMAIL=jaiminpate03042005@gmail.com \ | |
| -e PGADMIN_DEFAULT_PASSWORD=root123 \ | |
| -v pgadmin_data:/var/lib/pgadmin \ | |
| dpage/pgadmin4:latest" | |
| echo -e "Access at: http://localhost:5050" | |
| echo -e "Email: jaiminpate03042005@gmail.com, Password: root123\n" | |
| else | |
| echo -e "${RED}Skipping pgAdmin4${NC}\n" | |
| fi | |
| echo -e "${BLUE}=== Setup Complete ===${NC}" | |
| echo -e "\nRunning containers:" | |
| docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | |
| echo -e "\n${BLUE}Useful commands:${NC}" | |
| echo "Stop all: docker stop mongodb redis postgresql pgadmin4" | |
| echo "Remove all: docker rm mongodb redis postgresql pgadmin4" | |
| echo "Remove volumes: docker volume rm mongodb_data redis_data postgres_data pgadmin_data"#!/bin/bash | |
| # Colors for output | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| RED='\033[0;31m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color | |
| echo -e "${BLUE}=== Docker Services Starter ===${NC}\n" | |
| # Collect user preferences first | |
| echo -e "${BLUE}Please select which services to run:${NC}\n" | |
| read -p "Do you want to run MongoDB? (yes/no): " run_mongodb | |
| read -p "Do you want to run Redis? (yes/no): " run_redis | |
| read -p "Do you want to run PostgreSQL? (yes/no): " run_postgresql | |
| read -p "Do you want to run pgAdmin4? (yes/no): " run_pgadmin | |
| echo -e "\n${BLUE}Starting selected services...${NC}\n" | |
| # Function to check yes/no response | |
| is_yes() { | |
| case $1 in | |
| [Yy]* | [Yy][Ee][Ss]* ) return 0;; | |
| * ) return 1;; | |
| esac | |
| } | |
| # Function to start or create container | |
| start_or_create() { | |
| local container_name=$1 | |
| local run_command=$2 | |
| # Check if container exists | |
| if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then | |
| # Container exists, check if it's running | |
| if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then | |
| echo -e "${YELLOW}${container_name} is already running${NC}" | |
| else | |
| echo -e "${GREEN}Starting existing ${container_name}...${NC}" | |
| docker start ${container_name} | |
| echo -e "${GREEN}${container_name} started${NC}" | |
| fi | |
| else | |
| # Container doesn't exist, create it | |
| echo -e "${GREEN}Creating and starting ${container_name}...${NC}" | |
| eval $run_command | |
| echo -e "${GREEN}${container_name} created and started${NC}" | |
| fi | |
| } | |
| # MongoDB | |
| if is_yes "$run_mongodb"; then | |
| start_or_create "mongodb" "docker run -d \ | |
| --name mongodb \ | |
| -p 27017:27017 \ | |
| -e MONGO_INITDB_ROOT_USERNAME=admin \ | |
| -e MONGO_INITDB_ROOT_PASSWORD=root123 \ | |
| -v mongodb_data:/data/db \ | |
| mongo:latest" | |
| echo -e "Port: 27017, Username: admin, Password: root123\n" | |
| else | |
| echo -e "${RED}Skipping MongoDB${NC}\n" | |
| fi | |
| # Redis | |
| if is_yes "$run_redis"; then | |
| start_or_create "redis" "docker run -d \ | |
| --name redis \ | |
| -p 6379:6379 \ | |
| -v redis_data:/data \ | |
| redis:latest" | |
| echo -e "Port: 6379\n" | |
| else | |
| echo -e "${RED}Skipping Redis${NC}\n" | |
| fi | |
| # PostgreSQL | |
| if is_yes "$run_postgresql"; then | |
| start_or_create "postgresql" "docker run -d \ | |
| --name postgresql \ | |
| -p 5432:5432 \ | |
| -e POSTGRES_USER=postgres \ | |
| -e POSTGRES_PASSWORD=root123 \ | |
| -e POSTGRES_DB=mydb \ | |
| -v postgres_data:/var/lib/postgresql \ | |
| postgres:latest" | |
| echo -e "Port: 5432, Username: postgres, Password: root123, Database: mydb\n" | |
| else | |
| echo -e "${RED}Skipping PostgreSQL${NC}\n" | |
| fi | |
| # pgAdmin4 | |
| if is_yes "$run_pgadmin"; then | |
| start_or_create "pgadmin4" "docker run -d \ | |
| --name pgadmin4 \ | |
| -p 5050:80 \ | |
| -e PGADMIN_DEFAULT_EMAIL=jaiminpate03042005@gmail.com \ | |
| -e PGADMIN_DEFAULT_PASSWORD=root123 \ | |
| -v pgadmin_data:/var/lib/pgadmin \ | |
| dpage/pgadmin4:latest" | |
| echo -e "Access at: http://localhost:5050" | |
| echo -e "Email: jaiminpate03042005@gmail.com, Password: root123\n" | |
| else | |
| echo -e "${RED}Skipping pgAdmin4${NC}\n" | |
| fi | |
| echo -e "${BLUE}=== Setup Complete ===${NC}" | |
| echo -e "\nRunning containers:" | |
| docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | |
| echo -e "\n${BLUE}Useful commands:${NC}" | |
| echo "Stop all: docker stop mongodb redis postgresql pgadmin4" | |
| echo "Remove all: docker rm mongodb redis postgresql pgadmin4" | |
| echo "Remove volumes: docker volume rm mongodb_data redis_data postgres_data pgadmin_data" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment