This project serves as a starting point for Next.js applications using Docker, designed to streamline both development and deployment processes. It includes a Docker configuration tailored for Next.js apps and integrates Traefik for simplified reverse proxying and SSL configuration, ensuring a smoother workflow.
- 🐳 Docker Integration: Simplifies the setup and isolation of the development environment.
- 📦 Docker Compose Support: Facilitates the management of multi-container Docker applications.
- 📚 Pre-configured MongoDB: Ready-to-use MongoDB service for data storage.
- 🔄 Traefik Setup: Provides easy reverse proxying and automated SSL configuration for secure, production-ready deployments.
- 🌐 Development and Production Environment Setup: Offers an easy transition from development to production settings.
Before starting, please ensure the following tools are installed on your system:
- 🐳 Docker: Installation Guide
- 📦 Docker Compose: Installation Guide
- ⚙️ Traefik: Must be configured and running. Refer to the Traefik Quick Start for instructions. For an easy start, consider using this Traefik Docker Compose repository.
This template is built upon a solid foundation of technologies, each serving a crucial role:
Technology | Purpose |
---|---|
Frontend Framework | |
Containerization | |
Database | |
Reverse Proxy and SSL Termination |
Each technology is carefully chosen to ensure optimal performance, ease of use, and seamless integration for a smooth development experience and robust deployment.
Ensure Traefik is set up as a reverse proxy. Follow the Traefik Documentation if not already configured.
git clone https://github.com/SilberMa/docker-next-base.git your-project-name
cd your-project-name
This template assumes that Traefik is already set up as a reverse proxy. If you haven't configured Traefik yet, please follow the Traefik Documentation to do so. Make sure Traefik is configured to listen for incoming requests and route them appropriately to your Docker containers.
Navigate to the src directory and create your Next.js app:
cd src
npx create-next-app@latest .
Return to the root directory and start your application using Docker Compose:
cd ..
docker-compose up --build
This command constructs the Docker image for your Next.js app and initiates the services defined in the docker-compose.yml, including your Next.js app and MongoDB.
-
Next.js Application: The application is available at
https://dev.docker.localhost
. Make sure your Traefik setup is correctly configured to route this domain to your application container. -
MongoDB: Direct database connections can be made on port
27017
. -
Mongo Express: This web-based MongoDB admin interface is accessible at
http://localhost:8081
.
You may need to adjust the Dockerfile
to change the Node version or include additional dependencies specific to your project.
The docker-compose.yml
file outlines the service definitions for your application and database. Modify MongoDB's environment variables as needed to suit your project requirements. Ensure the Traefik labels in your service definitions align with your overall Traefik configuration to facilitate correct routing and SSL termination.
I deeply appreciate your interest in contributing to this project! Whether it's bug fixes, feature additions, or improvements to documentation, all contributions are welcome.
-
Fork the Repository: Click the 'Fork' button at the top right of this page to create your own copy of this repository.
-
Clone Your Fork: Get a local copy of your forked repository by running:
git clone https://github.com/your-username/docker-next-base.git
-
Create a New Branch: Navigate to your clone and checkout a new branch for your work:
cd docker-next-base
git checkout -b feature/YourFeatureName
-
Make Your Changes: Add, edit, or delete files as necessary for your contribution.
-
Commit Your Changes: Once you're happy with your work, commit the changes:
git commit -am "Add some amazing feature"
- Push to Your Fork: Upload your changes to GitHub:
git push origin feature/YourFeatureName
- Submit a Pull Request: Go to your fork on GitHub and click the 'New pull request' button. Choose your "feature/YourFeatureName" branch and ensure it's comparing against the main branch of the original repository. Fill in some details about your changes and submit the pull request.
When contributing to this project, please follow these guidelines:
- Code Style: Please adhere to the coding conventions used throughout the project to maintain consistency.
- Commit Messages: Write clear, concise commit messages that describe the changes you're making.
- Documentation: Update the README or other documentation as necessary based on your changes or new features.
Your contributions are invaluable to the project, and I look forward to reviewing your pull requests!
This project is open-sourced under the MIT License.