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?

【2026年版】WSLでDockerを使ってReact開発環境を作る(ざっくりメモ)

Last updated at Posted at 2026-01-30

前提となるディレクトリ構造:

project_root(フロントフォルダ+docker-compose.yml)
  ・docker-compose.yml
  frontend-react(フロントフォルダ)
   src(諸々)
   ・package.json
    ......(index.htmlなど、、)

1、Dockerなしで、React環境を作る。

cd project_root
mkdir frontend-react
cd frontend-react
yarn create vite .

2、エラー回避のため、frontend-react内に.yarnrc.ymlを作成
(最新のPnP方式ではなく、node_modules方式を強制するらしい。Dockerでは必要らしい。)

.yarnrc.yml
nodeLinker: node-modules

3、yarnを実行し改めてinstall

yarn

4、./frontend-react/package.jsonのdevを、"dev": "vite --host"にする

package.json
{
  "name": "frontend-react",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite --host", ←ここを変更

5、./frontend-react/Dockerfileを作成して、以下を書き込む

Dockerfile
FROM node:20-alpine

WORKDIR /frontend-react

COPY package.json yarn.lock .yarnrc.yml ./
RUN yarn install

COPY . .

EXPOSE 5173
CMD ["yarn", "dev"]

6、/project_root/docker-compose.ymlを作成して、以下を書き込む

docker-compose.yml
services:
frontend-react:
    build:
    context: ./frontend-react
    volumes:
    - ./frontend-react:/frontend-react
    - /frontend-react/node_modules
    ports:
    - "5173:5173"
    stdin_open: true
    tty: true

7、

docker compose up frontend-react

ホットリロード対応の開発環境の出来上がり。

おつかれさまでした。

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?