This repository provides a quick setup for developing Next.js applications using Docker with docker-compose. It's designed to facilitate VS Code container development without cluttering your host machine with Node.js modules, the Node runtime, npm, or other dependencies. Using Docker volumes for node_modules
and VS Code container dev dependencies allows for faster build times, especially when repeatedly removing and rebuilding the Docker container.
-
Clone this repository to your local machine:
git clone https://github.com/coredevel/nextjs-docker-compose.git cd nextjs-docker-compose
-
Run the Docker container:
docker-compose up --build
-
Access the development environment through VS Code by attaching to container and opening the
/usr/local/src/app
folder
By default, there's a run script at ./scripts/run.sh
that attempts to install dependencies from package.json on each container run.
You can comment out the 2nd line of the script if you find it undesirable for your use case.
To add new npm dependencies, either:
-
Open an integrated terminal while attached to the running container within VS code and run
npm install package-name
as usual; or -
Open a terminal to the container via docker exec:
docker exec -it name-of-container sh npm install package