What you will learn
- How to dockerize your Next.js application with OpenTelemetry via infrastack.ai
Prerequisites
- Docker installed on your machine
- An infrastack.ai account
- A Next.js application configured with the infrastack.ai SDK, see Integrate OpenTelemetry for Next.js with infrastack.ai
The application should be on the
nodejs
runtime. The edge
runtime is not supported at this time.Overview
Docker is a platform for building, running, and shipping applications with ease. With the power of infrastack.ai and OpenTelemetry, you can get comprehensive observability for your Next.js application. After you have configured your application with the infrastack.ai SDK by following the Integrate OpenTelemetry for Next.js with infrastack.ai guide, you can dockerize your application by following these steps:1
Configure next.config.mjs
In your This will allow the Next.js application to be run as a web service.
next.config.mjs
file, :2
Create a Dockerfile
Create a In this optimized dockerfile, we are using the
Dockerfile
in the root of your project with the following content:Dockerfile
base
image as the base image for the builder and runner stages. The builder
stage is used to build the application and the runner
stage is used to run the application.
You can change the port if you will not be using the default port of 3000.
3
Create a dockerignore file
Create a This will prevent unnecessary files from being included in the Docker image. You can add more files to the ignore list if you see fit.
.dockerignore
file in the root of your project with the following content:.dockerignore
4
Build the Docker image
Build the Docker image with the following command:
You can change the name
nextjs-example:latest
to your desired name and tag.5
Run the Docker container
Run the Docker container with the following command:
6
Visit your application
You can verify that the application is working by navigating to
http://localhost:3000
in your web browser.
Now, you can check your data in the infrastack.ai dashboard.
7
Optional: Deploy to a cloud provider
You can push the Docker image to a registry such as Docker Hub or GitHub Container Registry and then deploy it to a cloud provider of your choice.