-
Notifications
You must be signed in to change notification settings - Fork 14
Closed
Labels
.NETPull requests that update .NET codePull requests that update .NET codecontainersPull requests that update containers codePull requests that update containers codeenhancementNew feature or requestNew feature or request
Description
Description
Currently, the project uses manual Docker build/run commands and stores the SQLite database inside the container filesystem. This violates container immutability and doesn’t persist data between runs.
Proposed Solution
Introduce Docker Compose to:
- Automate image building and container orchestration
- Mount a Docker-managed volume to persist the SQLite database across container restarts
- Copy a pre-seeded
players-sqlite3.dbfrom the image to the volume only on first run
Suggested Implementation
docker-compose.yml
services:
api:
image: dotnet-samples-aspnetcore-webapi
container_name: aspnetcore-app
build:
context: .
dockerfile: Dockerfile
ports:
- "9000:9000"
volumes:
- storage:/storage/
environment:
- STORAGE_PATH=/storage/players-sqlite3.db
restart: unless-stopped
volumes:
storage:Dockerfile
# Entrypoint script and image-bundled, pre-seeded SQLite database
COPY --chown=root:root --chmod=755 scripts/entrypoint.sh ./entrypoint.sh
COPY --chown=root:root --chmod=755 storage ./docker-compose/storage
# Install SQLite runtime libs, add non-root user and prepare volume mount point
RUN adduser --disabled-password --gecos "" aspnetcore && \
mkdir -p /storage && \
chown -R aspnetcore:aspnetcore /storagescripts/entrypoint.sh
#!/bin/sh
set -e
IMAGE_STORAGE_PATH="/app/docker-compose/players-sqlite3.db"
VOLUME_STORAGE_PATH="/storage/players-sqlite3.db"
echo "✔ Starting container..."
if [ ! -f "$VOLUME_STORAGE_PATH" ]; then
echo "⚠️ No existing database file found in volume."
if [ -f "$IMAGE_STORAGE_PATH" ]; then
echo "Copying database file to writable volume..."
cp "$IMAGE_STORAGE_PATH" "$VOLUME_STORAGE_PATH"
echo "✔ Database initialized at $VOLUME_STORAGE_PATH"
else
echo "⚠️ Database file missing at $IMAGE_STORAGE_PATH"
exit 1
fi
else
echo "✔ Existing database file found. Skipping seed copy."
fi
echo "✔ Ready!"
echo "🚀 Launching app..."
exec "$@"Acceptance Criteria
docker compose upbuilds and runs the container with ASP.NET Core app on port 9000- SQLite DB is copied to the volume only if not already present
- Data persists after
docker compose downand is restored on nextup docker compose down -vresets the DB, and re-seeds it on next runREADME.mdis updated with Compose usage instructions
Metadata
Metadata
Assignees
Labels
.NETPull requests that update .NET codePull requests that update .NET codecontainersPull requests that update containers codePull requests that update containers codeenhancementNew feature or requestNew feature or request