Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run PostgreSQL locally without installing the server: define one PostgreSQL service in Docker Compose, keep its database files in a named volume, and use a Makefile for the commands you repeat. Bind the published port to 127.0.0.1 if host tools such as psql or a GUI client need access. The setup below uses the PostgreSQL 18 image layout documented by Docker.

Define one PostgreSQL service in Compose

Save this as compose.yaml in your project. It starts only the database container; your application and database client can run on the host.

services:
  db:
    image: postgres:18
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-dev}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
      POSTGRES_DB: ${POSTGRES_DB:-dev}
    ports:
      - "127.0.0.1:5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 5

volumes:
  postgres_data:

Docker’s current PostgreSQL guide uses the postgres:18 image and mounts a named volume at /var/lib/postgresql. For PostgreSQL 18 and later, the image uses a version-specific subdirectory under that parent path; mounting there also supports easier pg_upgrade --link upgrades. Do not carry forward the older /var/lib/postgresql/data mount convention without checking the image version. See Docker’s PostgreSQL guide.

The POSTGRES_PASSWORD interpolation makes Compose stop with an error if no password is supplied. Create a local .env file beside compose.yaml:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
POSTGRES_USER=dev
POSTGRES_PASSWORD=choose-a-local-password
POSTGRES_DB=dev

Keep real credentials out of committed files; add .env to .gitignore. These variables initialize a new, empty database directory. They are not a mechanism for changing the password, user, database, or initialization behavior of an already populated volume. The official image documents the variables and first-run behavior in its PostgreSQL image documentation.

Why use a named volume?

The container can be replaced while the database files remain. Compose creates the declared named volume when needed and reuses it on later runs; removing a container alone does not remove that data. Named volumes are the straightforward choice for most local setups. A bind mount instead exposes a specific host directory, which can be useful when direct host-file access matters but may introduce file ownership or permission problems. See Docker’s volume documentation.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Why bind the port to loopback?

127.0.0.1:5432:5432 makes the database available to programs on the same host through port 5432 without publishing it on the machine’s other network interfaces. Docker’s guide recommends loopback binding for a database intended for same-host access. If port 5432 is already occupied, change the host-side port, for example to 127.0.0.1:5433:5432, and connect your host client to port 5433; the container still listens on 5432.

Put routine operations behind Make targets

Save this as Makefile. The targets are a thin, readable interface to Compose; they do not change what Compose or PostgreSQL does.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
.PHONY: help up down ps logs psql wait reset

help:
	@echo "up      Start PostgreSQL"
	@echo "down    Stop and remove the container; keep database data"
	@echo "ps      Show service status"
	@echo "logs    Follow PostgreSQL logs"
	@echo "psql    Open psql inside the container"
	@echo "wait    Wait until PostgreSQL accepts connections"
	@echo "reset   DESTRUCTIVE: remove the container and database volume"

up:
	docker compose up -d

down:
	docker compose down

ps:
	docker compose ps

logs:
	docker compose logs -f db

psql:
	docker compose exec db sh -c 'exec psql -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"'

wait:
	@until docker compose exec -T db sh -c 'pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"' >/dev/null 2>&1; do 
		docker compose ps db; 
		sleep 1; 
	done
	@echo "PostgreSQL is accepting connections"

reset:
	@echo "DESTRUCTIVE: this removes the PostgreSQL volume and all its data."
	@echo "Run 'docker compose down -v' only if you intend to start with an empty database."
	@false

Use make help to see the available commands. Start the database with make up, check it with make ps, and follow its output with make logs. The make wait target repeatedly checks readiness from inside the container, which is useful before a host-run script or application attempts its first connection. Stop the service with make down; the named volume remains.

The reset target intentionally refuses to run the destructive command automatically. After confirming you want to delete the database, run docker compose down -v yourself. Docker documents that ordinary down preserves named volumes, while down -v removes them; see the volume reference.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Connect from host tools

With the default values in the example, a host-installed client can connect to localhost on port 5432 using database dev and user dev. For example:

psql -h 127.0.0.1 -p 5432 -U dev -d dev

psql prompts for the password. A GUI client uses the same host, port, database, username, and password fields. Alternatively, use make psql to launch psql inside the database container; that does not require installing psql on the host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Understand startup readiness and initialization

Running is not the same as ready

Compose’s normal startup ordering waits until a container is running, not until the service can accept database connections. Docker states: “On startup, Compose does not wait until a container is ‘ready’, only until it’s running.” The healthcheck above runs pg_isready; the make wait target gives host-run workflows a way to check readiness explicitly. If a separate application container is later added, configure its dependency on the database with condition: service_healthy so Compose waits for the healthcheck. See Docker’s startup-order guidance.

Changed environment values do not rewrite an existing database

The official PostgreSQL image applies initialization variables and scripts when it initializes an empty data directory. If the named volume already contains a database, changing POSTGRES_PASSWORD, POSTGRES_USER, POSTGRES_DB, or an initialization script does not reconfigure that existing database. Change database credentials through PostgreSQL itself when retaining the data is important. A fresh initialization requires deleting the volume, which erases its contents.

Named volume or bind mount?

Choice What it does Trade-off
Named volume Stores database files in Docker-managed storage and persists independently of the container. Simple lifecycle and reuse; inspect or manipulate its files through Docker rather than an ordinary project directory.
Bind mount Maps a chosen host path into the container. Direct host-path access, but permissions and ownership can be troublesome.

For a compact local database that host tools reach over a port, the named volume avoids coupling the database’s storage to a particular project folder. Either way, treat the stored files as valuable data: removing the container and removing its storage are different operations.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.