zkt26/prepare-app.sh

50 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# Uses the user's Bash interpreter to run this script
set -e
# Stops the script immediately if any command fails
echo "Preparing application..."
# Prints a message so the user knows the setup process has started
echo "Creating Docker network..."
# Prints a message before checking or creating the Docker network
docker network inspect mongo-crud-net >/dev/null 2>&1 || docker network create mongo-crud-net
# Tries to inspect the Docker network named "mongo-crud-net"
# >/dev/null hides normal output
# 2>&1 hides error output
# If the network does not exist, the command after || runs and creates it
echo "Creating Docker volume..."
# Prints a message before checking or creating the Docker volume
docker volume inspect mongo_crud_data >/dev/null 2>&1 || docker volume create mongo_crud_data
# Tries to inspect the Docker volume named "mongo_crud_data"
# If the volume does not exist, it creates it
# This volume will be used to store MongoDB data persistently
echo "Building application images..."
# Prints a message before building the Docker images
docker compose build
# Builds the Docker images defined in docker-compose.yml
# This usually builds the web app image and prepares everything needed to run the app
echo ""
# Prints an empty line for cleaner terminal output
echo "Preparation complete."
# Prints a message showing the setup finished successfully
echo "Created or verified:"
# Prints a heading for the summary of what now exists
echo " - network: mongo-crud-net"
# Shows the Docker network that was checked or created
echo " - volume: mongo_crud_data"
# Shows the Docker volume that was checked or created
echo " - images: built via docker compose"
# Shows that the Docker images were built from the Compose configuration