A simple and efficient Docker Compose setup for deploying Nextcloud with MySQL database backend.
This project provides a ready-to-use Nextcloud instance running in Docker containers. Nextcloud is a self-hosted file sync and collaboration platform that gives you control over your data.
- Easy Setup: One-command deployment using Docker Compose
- Persistent Storage: Data persists across container restarts
- MySQL Backend: Reliable MySQL 8.1 database
- Configurable: Environment-based configuration
- Auto-restart: Containers automatically restart on failure
Before you begin, ensure you have the following installed:
- Docker (version 20.10 or higher)
- Docker Compose (version 1.29 or higher)
git clone [email protected]:sumaiazaman/nextcloud.git
cd nextcloudCreate your .env file from the example template:
cp .env.example .envThen edit the .env file and change the default passwords:
nano .env
# or use your preferred editor: vim, code, etc.Update the following values:
# MySQL Configuration
MYSQL_ROOT_PASSWORD=your_secure_root_password_here
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud_user
MYSQL_PASSWORD=your_secure_password_here
# Nextcloud Configuration
NEXTCLOUD_PORT=8888Configuration Options:
MYSQL_ROOT_PASSWORD: Root password for MySQL (use a strong password)MYSQL_DATABASE: Database name (default:nextcloud)MYSQL_USER: Database user for Nextcloud (default:nextcloud_user)MYSQL_PASSWORD: Password for the database user (use a strong password)NEXTCLOUD_PORT: Port to access Nextcloud web interface (default:8888)
Security Note:
- Never commit your
.envfile with real passwords to version control - Use strong, unique passwords for production deployments
- The
.envfile is already in.gitignoreto prevent accidental commits
docker-compose up -dThis command will:
- Download the required Docker images (if not already present)
- Create and start the MySQL and Nextcloud containers
- Set up persistent volumes for data storage
Open your web browser and navigate to:
http://localhost:8888
Or replace localhost with your server's IP address if accessing remotely.
On first access, you'll see the Nextcloud setup wizard:
-
Create Admin Account: Choose a username and strong password
-
Database Configuration: The database is already configured via environment variables, but if prompted:
- Database user:
nextcloud_user(or your configuredMYSQL_USER) - Database password: Your
MYSQL_PASSWORD - Database name:
nextcloud - Database host:
mysql
- Database user:
-
Click Finish Setup
.
├── docker-compose.yml # Docker Compose configuration
├── .env.example # Environment variables template
├── .env # Your environment variables (create from .env.example)
└── README.md # This file
Note: The .env file is not included in the repository for security reasons. You must create it from .env.example.
docker-compose ps# All services
docker-compose logs -f
# Nextcloud only
docker-compose logs -f nextcloud
# MySQL only
docker-compose logs -f mysql docker-compose down docker-compose down -vWarning: This will delete all your Nextcloud files and database!
docker-compose restart docker-compose pull
docker-compose up -dData is stored in Docker volumes:
nextcloud_data: Nextcloud files and configurationdb_data: MySQL database files
These volumes persist even when containers are stopped or removed (unless you use docker-compose down -v).
- Change Default Passwords: Update all passwords in
.envbefore deployment - Use HTTPS: Consider setting up a reverse proxy (nginx/Traefik) with SSL certificates
- Firewall: Restrict access to the Nextcloud port
- Regular Backups: Backup your volumes regularly
- Keep Updated: Regularly update Docker images for security patches
- Check if containers are running:
docker-compose ps - Verify port is not in use:
netstat -tuln | grep 8888 - Check logs:
docker-compose logs nextcloud
- Ensure MySQL container is healthy:
docker-compose ps - Verify environment variables match in both services
- Check MySQL logs:
docker-compose logs mysql
docker-compose exec nextcloud chown -R www-data:www-data /var/www/htmlThis project is open source and available under the MIT License.
Contributions, issues, and feature requests are welcome!
For Nextcloud-specific issues, visit the official documentation.
Note: This is a basic setup suitable for personal use or small teams. For production environments, consider additional security measures, SSL/TLS encryption, and regular backups.