This repository contains the code implementation of the steps described in the blog posts titled:
- Nx + NextJS + Docker - The Nx way: Creating the NextJS application.
- Nx + NextJS + Docker - The Nx way: Containerizing our application
The blog post provides a detailed guide on setting up a Next.js application using Nx and Docker, following best practices and leveraging the capabilities of the Nx workspace.
The repository contains all the necessary code and configuration files to follow along with the steps outlined in the blog post.
To successfully run the Next.js application and Dockerize it, ensure that you have the following dependencies installed on your system:
- Docker (version 23)
- Node.js (version 18)
- pnpm (version 8)
You can alternatively use Volta to setup the right tooling for this project.
To get started, follow the steps below:
-
Clone the repository to your local machine:
git clone https://github.com/sebastiandg7/nx-nextjs-docker.git
-
Install the project dependencies:
pnpm install
-
Refer to the blog post for detailed instructions on how creating the Next.js application, setting up workspace libraries, and configuring the custom server build was done.
-
Once you have completed the steps and tested your application locally, you can follow the blog post for further instructions on how building the application for production and Dockerizing it efficiently was configured.
To build the NextJS application, run:
pnpm exec nx build my-app
You will find the build output in the dist/apps/my-app
directory.
To run the production build, run:
cd dist/apps/my-app
node server/main.js # Using the custom server
npm start # Using the NextJS built-in server
To build the NexJS application container, run:
pnpm exec nx container my-app
This will create a local image tagged as my-app:latest
.
Once the container image is built, you can start the container by running:
docker run -p 3000:3000 -t my-app:latest
Visit http://localhost:3000 to see the application running
Or call the API endpoint:
➜ curl http://localhost:3000/api/hello
Hello, from API!
For additional information and in-depth explanations of the steps involved, please refer to the blog posst:
- Nx + NextJS + Docker - The Nx way: Creating the NextJS application.
- Nx + NextJS + Docker - The Nx way: Containerizing our application
This project is licensed under the MIT License.