{"id":27944994,"url":"https://github.com/kristiyan-velkov/nextjs-prod-dockerfile","last_synced_at":"2026-02-11T06:04:04.003Z","repository":{"id":262604897,"uuid":"887752168","full_name":"kristiyan-velkov/nextjs-prod-dockerfile","owner":"kristiyan-velkov","description":"This repository offers a guide and examples to optimize Docker for deploying Next.js applications in production. It covers best practices for creating efficient, secure, and lightweight Docker images with multi-stage builds, standalone mode, and selective dependency management to enable faster builds and seamless production deployments.","archived":false,"fork":false,"pushed_at":"2025-02-20T23:37:50.000Z","size":467,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T12:55:33.709Z","etag":null,"topics":["code","docker","dockerfile","front-end","front-end-development","nextjs","programming","web"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristiyan-velkov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-13T08:16:03.000Z","updated_at":"2025-05-06T17:51:57.000Z","dependencies_parsed_at":"2025-01-09T10:36:51.519Z","dependency_job_id":"9291bf5b-c846-4043-8783-592bc0dae97b","html_url":"https://github.com/kristiyan-velkov/nextjs-prod-dockerfile","commit_stats":null,"previous_names":["kristiyan-velkov/nextjs-prod-dockerfile"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kristiyan-velkov/nextjs-prod-dockerfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristiyan-velkov%2Fnextjs-prod-dockerfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristiyan-velkov%2Fnextjs-prod-dockerfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristiyan-velkov%2Fnextjs-prod-dockerfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristiyan-velkov%2Fnextjs-prod-dockerfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristiyan-velkov","download_url":"https://codeload.github.com/kristiyan-velkov/nextjs-prod-dockerfile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristiyan-velkov%2Fnextjs-prod-dockerfile/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29327914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code","docker","dockerfile","front-end","front-end-development","nextjs","programming","web"],"created_at":"2025-05-07T12:55:30.952Z","updated_at":"2026-02-11T06:04:03.985Z","avatar_url":"https://github.com/kristiyan-velkov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./public/next.svg\" alt=\"Next.js Prod Dockerfile Logo\" /\u003e\n\u003c/div\u003e\n\nThis repository contains the configuration for running a Next.js 15 application using Docker. It supports development, production, and static export modes with three different Dockerfiles and a docker-compose.yml file.\n\n## More about me\n\n- [Blogs on Medium](https://medium.com/@kristiyanvelkov)\n- [LinkedIn](https://www.linkedin.com/in/kristiyan-velkov-763130b3/)\n\n---\n\n## Security\n\nThis Docker image has been thoroughly scanned for vulnerabilities to ensure a secure environment for your Next.js 15 application. The image has passed all vulnerability assessments using Docker's built-in security tools, including Docker Scout. Regular updates to the base image and dependencies are recommended to maintain a high level of security.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./public/docker-scout.png\" alt=\"Docker Scout check\" /\u003e\n\u003c/div\u003e\n\n- **Article**: [Docker Scout in Action](https://levelup.gitconnected.com/docker-scout-in-action-63e7c812532a?sk=120903755538c5065585d458d5e1eaa8)\n\n---\n\n## Prerequisites\n\n- Docker installed on your machine.\n- Make installed to use the Makefile commands.\n\n---\n\n## Usage\n\n| Command                | Description                          |\n| ---------------------- | ------------------------------------ |\n| `make help`            | Show available commands.             |\n| `make build`           | Build the Docker image.              |\n| `make run`             | Run the Docker container.            |\n| `make build-run`       | Build and run the Docker container.  |\n| `make stop`            | Stop the Docker container.           |\n| `make restart`         | Restart the Docker container.        |\n| `make logs`            | Show logs from the Docker container. |\n| `make clean`           | Remove Docker image and container.   |\n| `make clean-container` | Remove only the Docker container.    |\n| `make clean-image`     | Remove only the Docker image.        |\n\n---\n\n### Environment Variables\n\nThe following variables are defined in the `Makefile` and can be customized if needed:\n\n- `IMAGE_NAME`: The name of the Docker image. Default is `nextjs-app`.\n- `CONTAINER_NAME`: The name of the Docker container. Default is `nextjs-container`.\n- `HOST_PORT`: The port on the host machine that the container will map to. Default is `3000`.\n- `CONTAINER_PORT`: The port inside the Docker container where Nginx serves the application. Default is `80`. For dev use `3000`\n- `DOCKERFILE`: The Dockerfile to use. Default is `Dockerfile`. If you want to use standalone version of the build use Dockerfile.standalone -`NODE_VERSION`: The version of Node.js used in the base image. Default is `22.14.0-alpine`. This can be updated for easier migrations to newer versions.\n- `NGINX_VERSION`: The version of Nginx used in the export configuration. Default is `1.27.4-alpine`. This can be customized to match specific requirements or upgraded when necessary.\n\n---\n\n### Next.js Configuration\n\nTo configure the next.config.js file for different output options, use the following setup:\n\n```typescript\nimport type { NextConfig } from \"next\";\n\nconst nextConfig: NextConfig = {\n  // output: \"standalone\", // Use the Dockerfile.standalone file with this option\n  output: \"export\",\n};\n\nexport default nextConfig;\n```\n\n- **Standalone Mode**: Uncomment the line output: \"standalone\" if you want to use Dockerfile.standalone.\n- **Export Mode**: By default, this configuration uses output: \"export\", which enables static export of the Next.js app.\n\n---\n\n### How to Build and run the project under Docker\n\n1. **Build the Docker Image**:\n\n```bash\n  make build\n```\n\n2.  **Run the Docker Container**:\n\n```bash\n  make run\n```\n\n3. **Build and Run with a Single Command**\n   Alternatively, you can build and run in one step with:\n\n```bash\n make build-run\n```\n\n---\n\n## Deployment\n\nThis configuration is designed for deployment on environments where Docker is available. The Nginx server efficiently serves the static Next.js build, making it suitable for production use.\n\n---\n\n## Notes\n\n- Ensure Docker is properly configured to allow external access to port `3000` on the host machine if necessary.\n- Modify the Makefile variables as needed for custom image names, container names, and ports.\n\n---\n\n## Docker Compose with Watch Mode\n\nThis project supports watch mode for live reloading during development using Docker Compose. The docker-compose.yml file is configured to sync changes in your local project directory with the container and rebuild the service when key files change.\n\n```bash\ndocker compose up --watch\n```\n\n**Watch Mode Configuration: The develop section in the docker-compose.yml file includes:**\n\n- **Sync Changes**: Automatically syncs changes made in your local ./app directory with the /app directory inside the container. -**Rebuild Dependencies**: Automatically rebuilds the service when package.json changes, e.g., when you install a new package.\n- **File Syncing**: Changes to source files will be reflected inside the container in real-time. However, the node_modules folder is excluded to improve performance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristiyan-velkov%2Fnextjs-prod-dockerfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristiyan-velkov%2Fnextjs-prod-dockerfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristiyan-velkov%2Fnextjs-prod-dockerfile/lists"}