Docker
Learn how to containerize your TurboStarter app with Docker.
Docker is a popular platform for containerizing applications, making it easy to package your app with all its dependencies for consistent performance across environments. It simplifies development, testing, and deployment.
This guide explains how to containerize your TurboStarter app using Docker. You'll learn to create a Dockerfile, build a container image, and run your app in a container for a reliable and portable setup.
Configure Next.js for Docker
First of all, we need to configure Next.js to output the build files in the standalone format - it's required for the Docker image to work. To do this, we need to add the following to our next.config.js
file:
Create a Dockerfile
Dockerfile is a text file that contains the instructions for building a Docker image. It defines the environment, dependencies, and commands needed to run your app. You can safely copy the following Dockerfile to your project:
Feel free to check out our self-hosting guide for more details on how each stage of the Dockerfile works.
And that's all we need! You can now build and run your Docker image to deploy your app anywhere you want in an isolated environment.
Run a container
To test if everything works correctly, you can run a container locally with the following commands:
Make sure to also pass all the required environment variables to the container, so your app can start without any issues.
If everything works correctly, you should be able to access your app at http://localhost:3000.
That's it! You can now build and deploy your app as a Docker container to any supported hosting (e.g. Fly.io).
Using Docker containers is a great way to isolate your app from the host environment, making it easier to deploy and scale. It also simplifies the workflow if you're working with a team, as you can easily share the Docker image with your colleagues and they will run the app in the exact same environment.
Last updated on