This repo is based on the plain Node.js Dev Container with Next.js
This repo is the basis for Next.js projects that connect to a Postgres database (using Drizzle ORM) in a Docker container. Copy this repo when you start a new project and enhance the project from there.
- Docker Desktop
- Visual Studio Code
- VS Code Remote - Containers extension
-
Copy the environment file:
$ cp .env.example .env
-
Open the project in VS Code
-
When prompted, click "Reopen in Container". This will:
- Build the development container
- Install all dependencies
- Set up the PostgreSQL database
You can notice that everything worked when you can see the dev container name on the bottom left and the change of the VS Code color theme to September Steel.
-
Run the development server:
npm run dev
-
Apply changes to the database:
npx drizzle-kit push
Although the Docker and Dev container structure could be more minimal, this repo aims to have the files ready that you might enhance in the future:
docker-compose.yml: Contains the instructions to automate the creation of Docker images, the environment and application dependencies for a container..devontainer/devcontainer.json: Describes the settings, extensions, and environment for a development container in your code editor..devontainer/Dockerfile: Defines the steps required to build the Docker image, specifying the base image, environment variables, dependencies, commands, and configurations.
- Add relevant VS Code extensions
- Research how to prevent adding environment variables in
.envfor the database connection AND theDATABASE_URL-- ideally I don't want to change information on e.g.PGUSERandDATABASE_URL-- ideally, theDATABASE_URLgets constructed by the other variables