This setup provides isolated development containers for different technology stacks using Distrobox and Podman.
It also includes a shared PostgreSQL service running in Podman, connected through a custom Podman network called dev-net.
Recommended directory structure:
~/Code/
.
├── astro-dev
├── java-dev
├── js-ts-dev
├── python-dev
├── react-django-dev
├── react-express-dev
├── react-springboot-dev
└── services
└── postgres/
The development containers are created with their own home directories inside:
~/Documents/Code/<container-name>
For example:
~/Documents/Code/react-springboot-dev
The PostgreSQL service can be managed separately from:
~/Documents/Code/services/postgres
Before creating the development containers or PostgreSQL service, create a shared Podman network:
podman network create dev-netVerify that the network was created:
podman network lsYou should see dev-net in the list.
Define user and password:
export USER="USER"export PASSWORD="PASSWORD"Create and start a PostgreSQL container connected to the dev-net network:
podman run -d \
--name postgres-dev \
--network dev-net \
-e POSTGRES_USER=$USER \
-e POSTGRES_PASSWORD=$PASSWORD \
-e POSTGRES_DB=postgres \
-v postgres-dev-data:/var/lib/postgresql/data \
-p 5432:5432 \
docker.io/library/postgres:16This command creates a PostgreSQL container with:
| Option | Description |
|---|---|
--name postgres-dev |
Container name |
--network dev-net |
Connects PostgreSQL to the shared development network |
POSTGRES_USER=dev |
Database username |
POSTGRES_PASSWORD=secret |
Database password |
POSTGRES_DB=postgres |
Default database |
-v postgres-dev-data:/var/lib/postgresql/data |
Persistent PostgreSQL data volume |
-p 5432:5432 |
Exposes PostgreSQL on the host machine |
Check that the PostgreSQL container is running:
podman psYou can access the PostgreSQL service directly using:
podman exec -it postgres-dev psql -U dev -d postgresInside psql, you can list databases with:
\lCreate a new database:
CREATE DATABASE my_project_db;Connect to the new database:
\c my_project_dbList tables:
\dtExit psql:
\qThe script creates development containers using Distrobox.
Available stacks:
astro
js-ts
react-django
react-express
react-springboot
java
all
Make the script executable:
chmod +x create-dev-box.shCreate a React + Spring Boot development container:
./create-dev-box.sh react-springbootCreate a React + Django development container:
./create-dev-box.sh react-djangoCreate a React + Express development container:
./create-dev-box.sh react-expressCreate all containers:
./create-dev-box.sh allCreate a container with custom name:
# Base
./create-dev-box.sh stack container-name
# Example
./create-dev-box.sh python data-labThe backend-oriented containers are attached to the dev-net network so they can communicate with the PostgreSQL container.
These containers include:
| Stack | Main Tools |
|---|---|
react-django |
Node.js, pnpm, Python, pip, virtualenv, PostgreSQL client tools |
react-express |
Node.js, pnpm |
react-springboot |
Node.js, pnpm, Java, Maven, Gradle, Spring Boot CLI |
java |
Java, Maven, Gradle |
astro |
Node.js, pnpm |
js-ts |
Node.js, pnpm |
To enter a container manually:
distrobox enter react-springboot-devOr:
distrobox enter react-django-devOr:
distrobox enter react-express-devWhen connecting from another Podman container on the same network, do not use localhost.
Use the PostgreSQL container name as the host:
postgres-dev
Connection values:
DB_HOST=postgres-dev
DB_PORT=5432
DB_NAME=postgres
DB_USER=dev
DB_PASSWORD=secretThe reason is that localhost inside a development container refers to the development container itself, not the PostgreSQL container.
Inside a Spring Boot project, configure PostgreSQL in application.properties:
spring.datasource.url=jdbc:postgresql://postgres-dev:5432/postgres
spring.datasource.username=dev
spring.datasource.password=secret
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=trueOr using application.yml:
spring:
datasource:
url: jdbc:postgresql://postgres-dev:5432/postgres
username: dev
password: secret
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: trueInstall the PostgreSQL driver inside your Django virtual environment:
pip install psycopg[binary]Example settings.py database configuration:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "postgres",
"USER": "dev",
"PASSWORD": "secret",
"HOST": "postgres-dev",
"PORT": "5432",
}
}Run migrations:
python manage.py migrateInstall the PostgreSQL client:
pnpm add pgExample .env file:
DATABASE_URL=postgresql://dev:secret@postgres-dev:5432/postgresExample connection using pg:
import pg from "pg";
const { Pool } = pg;
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
const result = await pool.query("SELECT NOW()");
console.log(result.rows);Check that PostgreSQL is connected to dev-net:
podman inspect postgres-dev | grep -A 20 NetworksCheck that the development container is connected to dev-net:
podman inspect react-springboot-dev | grep -A 20 NetworksYou can also test connectivity from inside the development container:
distrobox enter react-springboot-devThen:
ping postgres-devIf ping is not installed, test using PostgreSQL tools or your application connection instead.
Start PostgreSQL:
podman start postgres-devStop PostgreSQL:
podman stop postgres-devRestart PostgreSQL:
podman restart postgres-devView PostgreSQL logs:
podman logs postgres-devFollow PostgreSQL logs:
podman logs -f postgres-devEnter PostgreSQL with psql:
podman exec -it postgres-dev psql -U dev -d postgresRemove the PostgreSQL container:
podman rm -f postgres-devRemove the PostgreSQL volume:
podman volume rm postgres-dev-dataWarning: removing the volume deletes the database data.
Start the PostgreSQL service:
podman start postgres-devCreate or enter your development container:
./create-dev-box.sh react-springbootOr enter an existing one:
distrobox enter react-springboot-devCreate your project inside the container home directory:
cd ~For example:
mkdir my-springboot-app
cd my-springboot-appConfigure the project to connect to PostgreSQL using:
postgres-dev:5432
Run your development server from inside the container.
Use postgres-dev as the database hostname when connecting from a development container.
Use localhost only when connecting from the host machine.
For example:
From the host:
localhost:5432
From a development container:
postgres-dev:5432
The PostgreSQL data is stored in the Podman volume:
postgres-dev-data
This allows the database data to persist even if the PostgreSQL container is stopped or recreated.
