LoginSignup
0
0

More than 1 year has passed since last update.

docker-composeでReactの開発環境作る。

Posted at

アウトプットを兼ねて、dockerを使ってReactAppを実装しようと思います。

まずはDockerfileとdocker-compose.ymlを用意します。

Dockerfile

FROM node:12.18.0-alpine
WORKDIR /usr/src/app
docker-compose.yml
version: '3'
services:
  react:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
     - ./:/usr/src/app
    command: sh -c "cd workplace && yarn start"
    ports:
     - "3000:3000"
    tty: true
docker-compose build

[+] Building 27.4s (6/6) FINISHED
これが表示されたらビルドは成功しています。
続いてcreate-react-appをコンテナ環境で実行できるようにしていきます。
同時にコマンドを実行してReactアプリをworkplaceディレクトリに作成していきます。

docker-compose run --rm react sh -c "npm install -g create-react-app && create-react-app workplace"
docker-compose up -d

Creating docker-react-project_react_1 ... done
これが表示されたらコンテナが立ち上がっているのでブラウザからlocalhost:3000
にアクセスしてみましょう。

image.png

Docker-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