working remote image

parent f2c43850
version: "3.8" version: "3.8"
services: services:
postgres: postgres:
build: # Use the new custom image from Docker Hub
context: ./postgres image: salmamohammedhamedmustafa/postgres:latest
dockerfile: Dockerfile
environment: environment:
POSTGRES_USER: ${POSTGRES_USER} POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
......
...@@ -17,7 +17,7 @@ COPY . . ...@@ -17,7 +17,7 @@ COPY . .
# Make the script executable # Make the script executable
RUN chmod +x wait-for-postgres.sh RUN chmod +x wait-for-postgres.sh
# Use the script as the entrypoint # Use the full path for the entrypoint
ENTRYPOINT ["/app/wait-for-postgres.sh"] ENTRYPOINT ["/app/wait-for-postgres.sh"]
# This is your application's original startup command # This is your application's original startup command
......
#!/bin/bash #!/bin/bash
# wait-for-postgres.sh
set -e set -e
host="postgres" host="postgres"
port="5432"
dbname="${POSTGRES_DB}"
user="${POSTGRES_USER}" user="${POSTGRES_USER}"
db="${POSTGRES_DB}"
password="${POSTGRES_PASSWORD}" password="${POSTGRES_PASSWORD}"
echo "Waiting for PostgreSQL..." echo "Waiting for PostgreSQL database to be ready..."
# Wait for the database server to be available
until PGPASSWORD="$password" pg_isready -h "$host" -U "$user"; do
echo "PostgreSQL server is unavailable - sleeping"
sleep 1
done
until PGPASSWORD=$password pg_isready -h $host -p $port -U $user; do # Wait for the specific database to be available
echo "PostgreSQL is unavailable - sleeping" until PGPASSWORD="$password" psql -h "$host" -U "$user" -d "$db" -c '\q'; do
echo "Database '$db' is not yet available - sleeping"
sleep 1 sleep 1
done done
echo "PostgreSQL is up - executing command" echo "PostgreSQL database is up and ready - executing command"
exec "$@" exec "$@"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment