![]() ![]() We should now be able to connect to the database using a tool like DBeaver or pgAdmin. Run the docker compose up to start the Postgres database and run the database init script. ![]() Let’s run Docker Compose and see it in action. Connect to the database and create a table called event.Grants all privileges for the user on the database.Create a database with whatever name is assigned to APP_DB_NAME.Create a new user with the name assigned to APP_DB_USER and the password assigned to APP_DB_PASS.Id CHAR(26) NOT NULL CHECK (CHAR_LENGTH(id) = 26) PRIMARY KEY,Īggregate_id CHAR(26) NOT NULL CHECK (CHAR_LENGTH(aggregate_id) = 26),ĬREATE INDEX idx_event_aggregate_id ON event (aggregate_id) GRANT ALL PRIVILEGES ON DATABASE $APP_DB_NAME TO $APP_DB_USER Psql -v ON_ERROR_STOP=1 -username "$POSTGRES_USER" -dbname "$POSTGRES_DB" <<-EOSQLĬREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS' mkdir dbĬreate a script called 01-init.sh touch db/01-init.shĪdd the following contents to it: #!/bin/bash Step 2: Create Database Init ScriptĬreate a folder called db to store our init script. This will allow us to connect to the database from our dev machine. We are also exposing the port to our host by assigning the Postgres port to the ports option. This is where we will place the database init script in the next step. The following environment variables are used by the init script to create a database user and a database for our application to use:įor the volumes option we are mapping a local folder called db to a folder inside the container at /docker-entrypoint-initdb.d/. The following environment variables are used to assign the username and password of the main Postgres database: The restart always makes sure the DB starts when the system starts. The healthcheck option is used to make sure Postgres is running before other services that depend on it can run. Here we are using version 13.1 of the official Postgres image. The image option specifies what Docker image to use. Step 1: Create Docker Compose fileįirst let’s create a folder to store our files: mkdir ~/postgres-demo & cd ~/postgres-demoĬreate a docker-compose.yml file: touch docker-compose.ymlĪdd the following contents to the file: version: '3' This tutorial shows you how to install it on Ubuntu 20.04. ![]() Before we beginįirst we need Docker and Docker Compose installed on our machine before we can do the steps in this tutorial. This tutorial shows you how to use Docker Compose to launch a Postgres image and create the database schema when it starts up for the first time. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |