Using Docker alone to enforce disk quota restrictions directly on files and directories isn't possible, as Docker containers don't inherently support filesystem-based quotas like userquota on the host's root filesystem. However, you can achieve a similar effect using application-level configurations.
While ProFTPD does not natively support disk quotas, you can use a workaround by implementing a custom solution to track directory sizes and deny further uploads when the limit is hit. Here's how you can achieve this using ProFTPD within Docker:
Approach with ProFTPD and Monitoring
-
Install Necessary Components: You will need to use ProFTPD with modules that can interact with an external script or configuration to manage quotas.
-
Create a Monitoring Script: Develop a script to monitor directory size and enforce limits.
-
Configure ProFTPD with Docker: Create a Docker Compose setup for ProFTPD and integrate the monitoring logic.
Step-by-Step Setup
-
Create a directory for your project:
mkdir proftpd-quota
cd proftpd-quota
-
Create docker-compose.yml:
version: '3.8'
services:
proftpd:
image: proftpd/proftpd:latest
container_name: proftpd-server
ports:
- "21:21"
- "30000-30009:30000-30009" # Passive ports for ProFTPD.
volumes:
- ./data:/home/ftpusers:rw
- ./proftpd.conf:/etc/proftpd/proftpd.conf:ro
environment:
- FTP_PASSIVE_PORTS=30000:30009
restart: unless-stopped
-
Create proftpd.conf to configure ProFTPD:
ServerName "ProFTPD Docker"
ServerType standalone
DefaultServer on
Port 21
<Global>
DefaultRoot ~
PassivePorts 30000 30009
</Global>
# Define the home location for the "buh" user
<Directory /home/ftpusers/buh>
# Your quota-enforcing script should deny excessive writes here.
HideHidden on
</Directory>
# Custom Log
ExtendedLog /var/log/proftpd/access.log WRITE,READ default
ExtendedLog /var/log/proftpd/auth.log AUTH auth
# Auth Configuration
AuthUserFile /etc/proftpd/ftpd.passwd
AuthGroupFile /etc/proftpd/ftpd.group
# Ban excessive uploads and monitor traffic
SQLLogFile /var/log/proftpd/sql.log
-
Add User Credentials: Create ftpd.passwd and ftpd.group files to set the username and passwords required, then update Docker configurations to map these files into the container.
-
Develop Monitoring Script: You can create a bash script that checks the directory size and interacts with ProFTPD by modifying user access based on conditions:
#!/bin/bash
USER_DIR="/home/ftpusers/buh"
QUOTA_LIMIT=$((300*1024*1024*1024)) # 300 GB in bytes
CURRENT_SIZE=$(du -s "$USER_DIR" | awk '{print $1}')
CURRENT_SIZE=$((CURRENT_SIZE * 1024)) # du gives KB
if [ "$CURRENT_SIZE" -ge "$QUOTA_LIMIT" ]; then
touch /home/ftpusers/buh/.quota-full
# More logic to deny further uploads
else
rm -f /home/ftpusers/buh/.quota-full
fi
-
Schedule Monitoring:
- Execute this script via a cron job at regular intervals on the host or inside a control container to check the directory size and take action by touching a special file or directly modifying permissions.
-
Launch Docker Compose:
docker-compose up -d
Limitations & Considerations
- This setup requires you to manage restrictions manually since Docker and FTP services don’t enforce I/O limits automatically.
- The script can only run on a host-level filesystem; ensure the script runs periodically to update the size based on actual data usage.
- Manual scripts have to connect to the ProFTPD user accounts management, possibly requiring access control lists or filesystem permission changes.
Using this script, you can approximate a disk quota system for your user "buh" without relying on filesystem-level quotas and avoiding remounting your FS with specific flags. For a more solid solution, you might consider integrating with solutions offering more complex storage logic, such as a distributed filesystem with built-in quota management.