This document provides comprehensive instructions for running FilesAPI using Docker containers.
- Docker Desktop or Docker Engine installed
- Docker Compose installed
-
Clone the repository and navigate to the project directory
git clone <repository-url> cd FilesAPI_9-master
-
Start all services
docker-compose up -d
-
Access the application
- FilesAPI: http://localhost:5100
- Swagger UI: http://localhost:5100/swagger
- MongoDB Express (Database UI): http://localhost:8081
-
Stop all services
docker-compose down
- Container:
filesapi-web - Port: 5100 (mapped to container port 8080)
- Environment: Production
- File Storage: Persistent volume mounted at
/app/uploads
- Container:
filesapi-mongodb - Port: 27017
- Username:
admin - Password:
password123 - Database:
filesapi - Data Persistence: Named volume
mongodb_data
- Container:
filesapi-mongo-express - Port: 8081
- Purpose: Web-based MongoDB administration interface
docker build -t filesapi:latest .docker run -d \
--name filesapi-mongodb \
-p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=password123 \
-e MONGO_INITDB_DATABASE=filesapi \
-v mongodb_data:/data/db \
mongo:7.0docker run -d \
--name filesapi-web \
-p 5100:8080 \
-e ConnectionStrings__DefaultConnection="mongodb://admin:password123@mongodb:27017/filesapi?authSource=admin" \
-v filesapi_uploads:/app/uploads \
--link filesapi-mongodb:mongodb \
filesapi:latestASPNETCORE_ENVIRONMENT: Set toProductionfor Docker deploymentASPNETCORE_URLS: Application URLs (default: http://+:8080)ConnectionStrings__DefaultConnection: MongoDB connection stringMongoDB__ConnectionString: Alternative MongoDB connection stringMongoDB__DatabaseName: MongoDB database name
- File Uploads:
/app/uploads- Stores uploaded files - MongoDB Data:
/data/db- Stores MongoDB database files
- The application runs as a non-root user (
appuser) for security - MongoDB is configured with authentication enabled
- Default credentials should be changed for production use
# Use development docker-compose override
docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d# Use production environment variables
docker-compose --env-file .env.production up -d# FilesAPI logs
docker logs filesapi-web
# MongoDB logs
docker logs filesapi-mongodb
# All services logs
docker-compose logs -f# FilesAPI container
docker exec -it filesapi-web /bin/bash
# MongoDB container
docker exec -it filesapi-mongodb mongosh# Stop and remove all containers and volumes
docker-compose down -v
docker system prune -f
# Rebuild and restart
docker-compose up -d --buildOnce the containers are running, you can test file uploads:
- Via Swagger UI: Navigate to http://localhost:5100/swagger
- Via curl:
curl -X POST "http://localhost:5100/api/storage" \ -H "Content-Type: multipart/form-data" \ -F "file=@/path/to/your/file.txt" \ -F "description=Test file upload"
- Increase Docker container memory limits
- Adjust MongoDB WiredTiger cache size
- Configure appropriate disk space for volumes
services:
filesapi:
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1Gdocker exec filesapi-mongodb mongodump --authenticationDatabase admin -u admin -p password123 --out /backup
docker cp filesapi-mongodb:/backup ./mongodb-backupdocker cp ./mongodb-backup filesapi-mongodb:/backup
docker exec filesapi-mongodb mongorestore --authenticationDatabase admin -u admin -p password123 /backup