---
title: "Running PostgreSQL, DBeaver and pgAdmin containers in Coder - Blog - Coder"
description: "Leveraging the flexibility of Kubernetes and Coder's embedding of a Terraform provisioner in its control plane, developers and data scientists can create powerful remote development environments that include databases and database administration tools in addition to their application container."
image: "/api/dynamic-og?title=Running+PostgreSQL%2C+DBeaver+and+pgAdmin+containers+in+Coder&randomBackground=true&styles=%7B%22height%22%3A162%2C%22width%22%3A302%2C%22padding%22%3A16%2C%22titleSize%22%3A24%2C%22logo%22%3A%7B%22width%22%3A80%2C%22height%22%3A12.15%7D%7D"
canonical: "https://coder.com/blog/running-postgresql-dbeaver-and-pgadmin-containers-in-coder"
---

Apr 2 20234 min read

# Running PostgreSQL, DBeaver and pgAdmin containers in Coder

[Mark Milligan](https://coder.com/blog/author/markmilligan)

Share this article

### Databases and remote development

Developers and data scientists sometimes need a database as part of their development environment configuration. In addition, they need a UI tool to visually connect to the database to view and manipulate the data.

You could try and smash all of these into one container but chances are you will run into dependency or container UID conflicts. You also may want to leverage each provider's published container image instead for ease of maintenance.

Coder's use of an embedded Terraform OSS provisioner and a touch of Kubernetes magic to run multiple containers in a single pod make it possible to build a Coder template that creates multiple containers, each running their respective application. All of this is possible with a flexible remote development environment platform like Coder. Users like developers and data scientists benefit from faster time to their first commit and no environment setup since Coder leverages open standards like Dockerfiles, container images and Kubernetes. DevOps and Platform Engineering benefit from fewer support tickets since these environment configurations, which we call templates, standardize environments across teams.

![Caption: Creating a new workspace with a 4 container template on Kubernetes](https://www.datocms-assets.com/19109/1680465560-template-create.png?fit=clip&fm=webp&w=3840&q=90)

### PostgreSQL, DBeaver, pgAdmin and Golang

In this example, we have a Golang app in one container, which also has the Coder agent to communicate with the user's IDEs and the Coder control plane. The template clones a public Golang app repo and uses environment variables passed to the container to know how to connect to PostgreSQL for making the app's API calls. We also have a container with PostgreSQL, a container with pgAdmin, and a container with DBeaver. pgAdmin and DBeaver are database administration tools popular with developers in the enterprise.

![Caption: The template's Terraform defining the DBeaver and pgAdmin application icons](https://www.datocms-assets.com/19109/1680465723-terraform-dbeaver-pgadmin-apps.png?fit=clip&fm=webp&w=3840&q=90)

### Container UIDs and Persistent Volumes

The PostgreSQL container needs to run with UID 999 and we specified a persistent volume claim for the container's directory that stores the database data. This allows the database data to persist if the Coder workspace and Kubernetes pod are stopped.

The DBeaver container has a UID of 0 aka `root` and also has a persistent volume claim to store database configuration settings defined during the first session. The pgAdmin container has a UID of 5050 and has its own persistent volume as well.

![Caption: The template's Terraform defining the containers and UIDs in the Kubernetes pod spec](https://www.datocms-assets.com/19109/1680465813-terraform-pod-spec.png?fit=clip&fm=webp&w=3840&q=90)

### Dotfiles, CPU, Memory and Disk Parameters

At workspace creation, the developer or data scientist selects the template and is prompted for inputs like their dotfiles repository, CPU, memory and disk for each of the four containers. These inputs leverage Coder parameters and are mutable for future adjustments.

Coder templates include a markdown file which is visible in the template UI. In this example, the markdown explains how to use pgAdmin and DBeaver and includes instructions on how to run database migrations and run `curl` commands to retrieve data from the PostgreSQL database.

![Caption: The template's markdown explaining what will be included in the workspace](https://www.datocms-assets.com/19109/1680466053-template-markdown.png?fit=clip&fm=webp&w=3840&q=90)

### Localhost and Container Intercommunication

Any container in the Kubernetes pod can communicate on `localhost.` This is how the Golang app, DBeaver and pgAdmin can find the PostgreSQL database. Within the `coder_app` resource of the template, each IDE references a process running on a port on `localhost.`

### Accessing PostgreSQL in the Development Environment

After creating the development environment, PostgreSQL, DBeaver and pgAdmin start automatically as defined in the entrypoint of their respective containers. The Coder agent starts in the Golang container. Open DBeaver and pgAdmin using the icons in the Coder workspace UI.

![Caption: A running Coder workspace as a Kubernetes pod and 4 containers for Golang, PostgreSQL, DBeaver and pgAdmin](https://www.datocms-assets.com/19109/1680469916-multi-container-workspace-meta.png?fit=clip&fm=webp&w=3840&q=90)

### Running Database Migrations and Accessing PostgreSQL from the Golang app

In the template's `startup_script` a sample Golang app is cloned from GitHub. After the development environment is created, the developer must run a couple scripts in the Golang repo to run migrations to populate the PostgreSQL database. The Golang app also starts and listens on a port for API calls on `localhost` to add to and query from the database.

![Caption: Starting the Golang server and retrieving a row from the authors table](https://www.datocms-assets.com/19109/1680468014-go-api-to-data.png?fit=clip&fm=webp&w=3840&q=90)

### Accessing PostgreSQL from DBeaver

DBeaver is a popular database administration tool. It is browser-based so Coder accesses it on a subdomain in a `coder_app.` Configuration settings like the location and credentials to the PostgreSQL container are stored in a persistent volume claim.

![Caption: Connecting to the PostgreSQL database container during initial setup with DBeaver](https://www.datocms-assets.com/19109/1680469008-dbeaver-data.png?fit=clip&fm=webp&w=3840&q=90)

![Caption: Retrieving rows from the persons table with DBeaver](https://www.datocms-assets.com/19109/1680468144-dbeaver-data.png?fit=clip&fm=webp&w=3840&q=90)

### Accessing PostgreSQL from pgAdmin

pgAdmin is also a popular database administration tool specific to PostgreSQL. It is browser-based so Coder accesses it on a subdomain in a `coder_app.` Configuration settings like the location and credentials to the PostgreSQL container are stored in a persistent volume claim.

![Caption: The pgAdmin login screen](https://www.datocms-assets.com/19109/1680468327-pgadmin-login.png?fit=clip&fm=webp&w=3840&q=90)

![Caption: Retrieving rows from the persons table with pgAdmin](https://www.datocms-assets.com/19109/1680468364-pgadmin-data.png?fit=clip&fm=webp&w=3840&q=90)

### Accessing PostgreSQL from `psql`

`psql` is a terminal-based front-end to PostgreSQL. Users open a web terminal or locally `ssh` into the development environment to run `psql` commands. The example installs `psql` in the `startup_script` but it could be just as easily installed in the Golang container which the terminal connects to via the Coder agent.

![Caption: Retrieving a row of data with the psql utility inside a web terminal](https://www.datocms-assets.com/19109/1680468521-psql-data.png?fit=clip&fm=webp&w=3840&q=90)

### Source for the Example

This example template is available from [sharkymark's GitHub v2 template repository.](https://github.com/sharkymark/v2-templates/tree/main/k8s-multi-container)

### Subscribe to our newsletter

Want to stay up to date on all things Coder? Subscribe to our monthly newsletter for the latest articles, workshops, events, and announcements.
