Skip to content

Commit 1a386d2

Browse files
ericfitzclaude
andcommitted
fix: use Docker named volume for PostgreSQL data directory
Chainguard PostgreSQL image runs as non-root postgres user, which cannot chmod host bind mounts on Docker Desktop for macOS. Switch to a Docker named volume so the container can manage permissions correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ecbdd11 commit 1a386d2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,20 @@ start-database:
157157
if [ -z "$$DATABASE" ]; then DATABASE="tmi_dev"; fi; \
158158
IMAGE="$(INFRASTRUCTURE_POSTGRES_IMAGE)"; \
159159
if [ -z "$$IMAGE" ]; then IMAGE="tmi/tmi-postgresql:latest"; fi; \
160-
DATA_DIR="$$HOME/Projects/tmi-postgres-data"; \
161-
mkdir -p "$$DATA_DIR"; \
160+
VOLUME_NAME="tmi-postgres-data"; \
161+
if ! docker volume ls --format "{{.Name}}" | grep -q "^$$VOLUME_NAME$$"; then \
162+
docker volume create $$VOLUME_NAME > /dev/null; \
163+
fi; \
162164
if ! docker ps -a --format "{{.Names}}" | grep -q "^$$CONTAINER$$"; then \
163165
echo -e "$(BLUE)[INFO]$(NC) Creating new PostgreSQL container..."; \
164-
echo -e "$(BLUE)[INFO]$(NC) Mounting data directory: $$DATA_DIR"; \
166+
echo -e "$(BLUE)[INFO]$(NC) Using Docker volume: $$VOLUME_NAME"; \
165167
docker run -d \
166168
--name $$CONTAINER \
167169
-p 127.0.0.1:$$PORT:5432 \
168170
-e POSTGRES_USER=$$USER \
169171
-e POSTGRES_PASSWORD=$$PASSWORD \
170172
-e POSTGRES_DB=$$DATABASE \
171-
-v "$$DATA_DIR:/var/lib/postgresql/data" \
173+
-v "$$VOLUME_NAME:/var/lib/postgresql/data" \
172174
$$IMAGE; \
173175
elif ! docker ps --format "{{.Names}}" | grep -q "^$$CONTAINER$$"; then \
174176
echo -e "$(BLUE)[INFO]$(NC) Starting existing PostgreSQL container..."; \
@@ -187,7 +189,8 @@ clean-database:
187189
$(call log_warning,"Removing PostgreSQL container and data...")
188190
@CONTAINER="$(INFRASTRUCTURE_POSTGRES_CONTAINER)"; \
189191
if [ -z "$$CONTAINER" ]; then CONTAINER="tmi-postgresql"; fi; \
190-
docker rm -f $$CONTAINER 2>/dev/null || true
192+
docker rm -f $$CONTAINER 2>/dev/null || true; \
193+
docker volume rm tmi-postgres-data 2>/dev/null || true
191194
$(call log_success,"PostgreSQL container and data removed")
192195

193196
start-redis:

0 commit comments

Comments
 (0)