postgres / entrypoint.sh
bpandey23's picture
Create entrypoint.sh
36faa5c verified
raw
history blame
883 Bytes
#!/bin/bash
# Set the environment variables for the PostgreSQL database
export POSTGRES_DB=my_database
export POSTGRES_USER=my_username
export POSTGRES_PASSWORD=my_password
# Create the PostgreSQL database and user
su - postgres -c "psql -c \"CREATE DATABASE $POSTGRES_DB;\""
su - postgres -c "psql -c \"CREATE USER $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';\""
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;\""
# Create a table and insert sample data
su - postgres -c "psql -d $POSTGRES_DB -c \"
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) UNIQUE NOT NULL
);
INSERT INTO users (name, email) VALUES
('John Doe', '[email protected]'),
('Jane Smith', '[email protected]');
\""
# Start the PostgreSQL service
exec postgres