0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

docker: next.js

Posted at

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"
  },
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?