Back to all posts

Run PostgreSQL in Docker with NVDA

Inspect the PostgreSQL service, connect with psql, create a practice database and verify the result using VS Code and NVDA.

Watch the video

Loading this video connects you to YouTube (Google), which receives your IP address and may store or read information on your device for playback and advertising. YouTube may show ads. Choose Load YouTube video to allow this for this video. See Google's privacy policy.

Watch Now add the Database for our Tic Tac Toe Game while using NVDA Screen Reader on YouTube

This lesson adds a PostgreSQL database to the tic tac toe development project. I inspect the Docker Compose service, connect to PostgreSQL, create a database called tictactoe, and read the result with NVDA. By the end you have an empty practice database ready. Game tables and connecting the interface come later.

Start from the game project

Have Docker Desktop installed and follow my run the game walkthrough. Open the repository in VS Code, with your terminal at its root beside compose.yaml. I use WSL Ubuntu in VS Code for this demonstration.

The repository has changed since the August lesson, and today's download also includes the Django API. The commands below use the database service name, which is the same in both versions, so keep the current Compose file as it is.

Read the database service

In compose.yaml, find the service named database. The recording uses the postgres:17 image, restart: unless-stopped, the POSTGRES_PASSWORD environment variable, and a named postgres_data volume mounted at /var/lib/postgresql/data. That volume keeps database files outside the container's writable layer.

The sample password is for local development only, and the current project does not publish PostgreSQL's port to your computer. The project README has the current configuration.

Start and inspect PostgreSQL

Run these from the project root:

docker compose up -d
docker compose ps
docker compose exec database pg_isready -U postgres

The readiness command is an additional check from the current README. The video uses docker ps to inspect running containers. In VS Code, Ctrl+Backtick (the grave accent key) opens the integrated terminal. Alt+F2 opens Accessible View so you can read long output a line at a time; Escape returns to the terminal.

Connect with psql

The word database below is the Compose service name. It is not the name of the database we are about to create. The uppercase U selects the PostgreSQL user:

docker compose exec database psql -U postgres

You should reach a PostgreSQL prompt. From there, use the psql command below to list databases. It is a backslash followed by lowercase L, not a slash or the number one:

\l

Create and verify the practice database

If tictactoe is not already listed, enter this SQL statement, including its semicolon:

CREATE DATABASE tictactoe;

A successful statement reports CREATE DATABASE. Run the list command again and find tictactoe in the output:

\l

If it is already there, keep using it rather than deleting it. See the PostgreSQL psql reference for listing and session commands.

Leave psql and stop the project

I use Ctrl+D to leave psql in the WSL terminal. You can also enter its quit command:

\q

Back at the shell prompt, stop the project and check its containers:

docker compose down
docker compose ps

A normal down keeps the named volume, so your database is still there next time. Adding --volumes removes those volumes, so leave it off. In the Django API lesson, I build a service that connects to PostgreSQL and checks its health.

Analytics choices

May I use Google Analytics to understand which pages people read? If you accept, Google receives information about your visits and device, and stores analytics cookies in your browser. You can decline and still use the whole site.

If you close this dialog without choosing, analytics stays off and you will not be asked again on this device for 180 days. You can change your choice at any time using Analytics choices at the bottom of the page. Your choice is remembered for 180 days. Read the privacy policy.