A development setup for Strapi with MySQL, using Docker for containerization and including migration and seeding capabilities.
- Docker and Docker Compose
- Node.js
- npm or yarn
- Git
- Clone the repository:
cd test-cog
- Install dependencies:
npm install
- Start the development environment:
make setup
This will:
- Build and start all Docker containers
- Run database migrations
- Seed the database with test data
# Start the development environment
make setup
# Start containers
make up
# Stop containers
make down
# View logs
make logs
# Access Strapi container shell
make shell
# Access MySQL shell
make mysql
# Restart containers
make restart
# Run migrations
make migrate
# Run seeds
make seed
- Strapi Admin: http://localhost:1337/admin
- phpMyAdmin: http://localhost:8080
- Server: mysql
- Username: strapi
- Password: strapi_password
Create a new migration:
npm run migrate:make migration_name
Run migrations:
make migrate
Rollback migrations:
npm run migrate:rollback
Create a new seed file:
npm run seed:make seed_name
Run seeds:
make seed
- Strapi: Node.js 14 Alpine
- MySQL: 8.0
- phpMyAdmin: Latest
Default ports:
- Strapi: 1337
- MySQL: 3306
- phpMyAdmin: 8080
Create a .env
file in the root directory:
HOST=0.0.0.0
PORT=1337
DATABASE_HOST=mysql
DATABASE_PORT=3306
DATABASE_NAME=test_cog
DATABASE_USERNAME=strapi
DATABASE_PASSWORD=strapi_password
- MySQL connection issues:
# Check MySQL container status
docker compose ps
# View MySQL logs
docker compose logs mysql
- Strapi startup issues:
# Check Strapi logs
docker compose logs strapi
# Access Strapi container
make shell
- Migration/Seed failures:
# Reset database and run migrations again
make migrate
make seed
- Make changes to your code
- Test locally using the development environment
- Create migrations for database changes
- Update seeds if necessary
- Commit your changes
- Push to repository
To run tests:
npm run test
# View running containers
docker compose ps
# View container logs
docker compose logs -f [service_name]
# Rebuild containers
docker compose build --no-cache
# Remove all containers and volumes
docker compose down -v
# Clean up Docker system
docker system prune -af
Backup database:
make backup
Restore database:
make restore
Regular maintenance tasks:
- Update dependencies
- Backup database
- Check logs for errors
- Monitor disk space
- Update Docker images
-
Container won't start:
- Check logs:
docker compose logs [service_name]
- Verify environment variables
- Check port conflicts
- Check logs:
-
Database connection issues:
- Verify MySQL is running:
docker compose ps
- Check database credentials
- Ensure migrations have run
- Verify MySQL is running:
-
Permission issues:
- Check file ownership in containers
- Verify volume permissions
AI used for reviewing and testing this project.