Prerequisites
Docker Installation
Install Docker on your system:User Permissions
Adding www-data to Docker Group
The web server user (typicallywww-data) needs permission to run Docker containers.
Verify Group Membership
Check that the user was added successfully:docker listed in the output.
Restart Services
After adding the user to the docker group, restart the web server:Docker Container Configuration
Required Images
Wecode needs Docker images for different programming languages. Pull the necessary images:Custom Images
You may need to create custom Docker images with specific compilers or libraries:Dockerfile
Testing Docker Setup
Basic Connectivity Test
Test that Docker is accessible:Run Test Container
Test running a simple container:Test as Web Server User
Switch to the web server user and test Docker access:Test Code Execution
Test executing code in a container:Hello, World! in the output.
Security Considerations
Resource Limits
Always set resource limits when running containers:--memory- Maximum memory usage--memory-swap- Maximum swap usage (set equal to memory to disable swap)--cpus- Number of CPU cores--pids-limit- Maximum number of processes--network=none- Disable network access
Read-Only Mounts
Mount source code as read-only:Non-Root User
Run containers as a non-root user:Timeout Enforcement
Always enforce timeouts for code execution:No Privileged Containers
Never use--privileged flag when running untrusted code:
Disable Capabilities
Drop unnecessary Linux capabilities:Storage Management
Clean Up Old Containers
Regularly clean up stopped containers:Clean Up Old Images
Remove unused images:Automated Cleanup
Set up a cron job for regular cleanup:Monitoring
Check Running Containers
View Container Logs
Monitor Resource Usage
Troubleshooting
Permission Denied
Problem:permission denied while trying to connect to the Docker daemon socket
Solution:
- Verify the user is in the docker group:
groups www-data - Restart the web server:
sudo systemctl restart apache2 - If still failing, reboot the system
Docker Daemon Not Running
Problem:Cannot connect to the Docker daemon
Solution:
Container Timeout
Problem: Containers hang or don’t stop Solution:- Force kill hung containers:
docker kill <container_id> - Set explicit timeouts:
timeout 30s docker run ...
Disk Space Issues
Problem: No space left on device Solution:Installation Script Reference
Frominstall.sh, the Docker setup is handled during the installation process:
setup.sh script clones the repository and runs the installation:
Best Practices
- Isolation: Always run code in isolated containers with no network access
- Resource Limits: Set strict CPU, memory, and process limits
- Timeouts: Enforce maximum execution time for all submissions
- Monitoring: Regularly monitor Docker resource usage
- Updates: Keep Docker and images up to date with security patches
- Cleanup: Implement automated cleanup of old containers and images
- Testing: Regularly test the Docker setup with sample submissions
- Logs: Monitor Docker logs for suspicious activity

