Image to run NextJS apps in docker.
docker buildx build --tag davidetriso/nextjs[tagname-dir_name] -o type=image --platform=linux/arm64,linux/amd64 ./[tagname-dir_name]
E.g.:
docker buildx build --tag davidetriso/nextjs:node-14.15 -o type=image --platform=linux/arm64,linux/amd64 ./node-14.15
docker push davidetriso/nextjs:tagname
E.g.:
docker push davidetriso/nextjs:node-14.15
Execute the ./build-and-push.sh
script to build and push all images to Docker Hub at once.
Mount your app code in the /app
dir inside the container using bind mounts; the node_modules
and .next
directories can be excluded, because they will be populated by the image in runtime.
For example, in a compose file add:
volumes:
- ./:/app
# exclude the node_modules and .next directories with 'empty' mounts
- /app/node_modules
- /app/.next
By default the image will start a production server.
To start the application in dev mode, set the ENV
var to dev
.
For example, in a compose file add:
environment:
ENV: dev
NOTE: When the container is launched, and no
package.json
file is found in the/app
directory, the entrypoint script will trigger the creation of a new Next.js application with default configurations (applicable for images running Node versions >= 18.18).
Licensed under the terms of the MIT license.