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?

Next.jsのtutorialをやるDockerの環境が欲しい

Posted at

やりたいこと

これを始めようと思ったけど、とにかく自分のパソコン(以下ホストマシン)でnodeやらnpm i などやら実行するのが嫌なので、Dockerでコンテナを立てるまでの記録です。
めちゃくちゃ簡易に作成したものなので色々不足はありますが最低限の構築として。

目標

Getting Startedの以下のコマンドをコンテナ内で実行する

npx create-next-app@latest nextjs-dashboard --example "https://github.com/vercel/next-learn/tree/main/dashboard/starter-example" --use-pnpm

手順

構成の準備

nextjs-dashboard
├── Dockerfile
└── docker-compose.yml
Dockerfile
FROM node:18.17.1

WORKDIR /app
docker-compose.yaml
version: '3'
services:
  app:
    build:
      context: .
    volumes:
      - .:/app
    tty: true
    ports:
      - "3000:3000"

このtty: true が肝なんですよね。今回run devとかしないでコンテナ内で色々やりたいので、これを書かないと起動した瞬間終了してしまいます。
初めて使うけど、本来の用途なのかは不明です。とりあえず「コンテナ内で仮想ターミナルを有効にして、コンテナが終了しないようにする設定」という認識でいいと思います。

コマンド

こちらの記事を参考にさせていただきました。

docker-compose build
docker-compose run --rm app sh

これは「一時的にコンテナを起動して、shシェルを実行し、終了後にそのコンテナを自動的に削除するよ」という事です。
シェルに入ると思うので、その中で以下実行します。

npm install -g pnpm
npx create-next-app@latest nextjs-dashboard --example "https://github.com/vercel/next-learn/tree/main/dashboard/starter-example" --use-pnpm

以上で完了です。

まとめ

ホストマシンに何も入れたくない自分みたいな人間は割とよくやる事になりそうな手順でしたので、備忘録までに投稿しました。
tty: true くんはこの後どうなるのでしょうか。そして彼の行方を知る者はどこにも居ませんでした。

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?