Pre-Requisites
Project Setup and Frontend Initialization
- Create project directory:
- Create frontend directory:
- Initialize the Next.js project with our preferences built into the command (non-interactive in the container):
or to see options run:
- Create a Dockerfile.dev:
These steps have successfully set up our Next.js frontend environment within a Docker container. We now have a Next.js project with TypeScript, ESLint, Tailwind CSS, and the App Router, along with a Dockerfile for development.
Now let’s test our Dockerfile and setup:
Transclude of next.js-frontend-docker-build-and-run-commands
The default NextJS page is now visible on my browser localhost:3000!
Debug
You may get an error such as: Bind for 0.0.0.0:3000 failed: port is already allocated
If so, following commands are useful:
Docker cleanup commands
Final Steps for this step
- Update ownership of project files (chown)
- Push changes to a remote repository - consider Initialize a new GitHub Repo
Filetree state
Our project should currently look like this: