前提・実現したいこと
DockerでRuby on Rails + Reactを別々にアプリ作成する環境構築手順 - Qiita
↑のページを参考に、
- api : rails
- フロント : React
という構成で環境構築を行ないました。
参考にしたページによると、
- localhost:3000 : Railsのページ
- localhost:8000 : Reactのページ
を開くと書いてありますが、私の環境ではChromeでlocalhost:8000にアクセスしても、下図のページになります。
localhost:3000にアクセスすると、私の環境でもRailsのページを開きます。
localhost:8000にアクセスすることで、下図のようにReactのページを開きたいです。
バージョン
- Docker 19.03.8
該当のソースコード
ディレクトリ構成
. ├── docker-comose.yml ├── api │ ├── Dockerfile │ └── rails new で作成したファイル群 └── front ├── Dockerfile └── react-sample └── create-react-appで作成したファイル群
docker-compose.yml
yml
1version: '3' 2 3services: 4 db: 5 image: postgres 6 volumes: 7 - postgres-data:/var/lib/postgresql/data 8 api: 9 build: 10 context: ./api/ 11 dockerfile: Dockerfile 12 command: /bin/sh -c "rm -f /myapp/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 13 image: rails:dev 14 volumes: 15 - ./api:/myapp 16 - ./api/vendor/bundle:/myapp/vendor/bundle 17 environment: 18 TZ: Asia/Tokyo 19 RAILS_ENV: development 20 ports: 21 - 3000:3000 22 depends_on: 23 - db 24 front: 25 build: 26 context: ./front/ 27 dockerfile: Dockerfile 28 volumes: 29 - ./front:/usr/src/app 30 command: sh -c "cd react-sample && yarn start" 31 ports: 32 - "8000:3000" 33volumes: 34 postgres-data: 35 driver: local
試したこと
command: sh -c "cd react-sample && yarn start"
あなたの回答
tips
プレビュー