next.js with mongodb in Docker
dev環境
docker-compose.yml
version: '3.8'
services:
web:
image: node:alpine
working_dir: /home/node/app
volumes:
- ./:/home/node/app
ports:
- 3000:3000
command: npm run dev:calledFromDockerCompose
db:
image: mongo
volumes:
- ./db:/data/db
ports:
- 27017:27017
production環境
docker-compose-production.yml
version: '3.8'
services:
web:
image: node:alpine
working_dir: /home/node/app
volumes:
- ./:/home/node/app
ports:
- 3000:3000
command: ash -c "npx next build && npx next start"
db:
image: mongo
volumes:
- ./db:/data/db
コマンド
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "pages/index.tsx",
"scripts": {
"dev": "docker-compose up",
"dev:stop": "docker-compose down",
"dev:calledFromDockerCompose": "NODE_OPTIONS='--inspect' npx next dev",
"production": "docker-compose -f docker-compose-production.yml up -d",
"production:stop": "docker-compose -f docker-compose-production.yml down"
},