LoginSignup
0
0

More than 1 year has passed since last update.

【Docker】React+Nginxの環境を作ろうとしたときのエラー

Posted at

Dockerでビルド時にエラーが出たのでとりあえずの解決策があったのでメモ
※間違っていた場合、コメントで教えていただけると幸いです

React+Nginxの環境をDockerで作ろうと思い、こちらのサイト(How to Serve a React App with nginx in Docker)を参考に構築を行った。

  1. reactアプリの作成
    yarn create react-app {プロジェクト名} --template typescript
    作成したプロジェクトに移動

2.Dockerfileの作成
touch Dockerfile
私はここでDockerfileをタイポしていたのでお気をつけて・・・

3. .dockerignoreの作成
echo "node_modules" > .dockerignore

4. Dockerfileの記述

# Multi-stage
# 1) Node image for building frontend assets
# 2) nginx stage to serve frontend assets

# Name the node stage "builder"
FROM node:10 AS builder
# Set working directory
WORKDIR /app
# Copy all files from current directory to working dir in image
COPY . .
# install node modules and build assets
RUN yarn install && yarn build

# nginx state for serving content
FROM nginx:alpine
# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html
# Remove default nginx static assets
RUN rm -rf ./*
# Copy static assets from builder stage
COPY --from=builder /app/build .
# Containers run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"]

5. docker build
docker build -t {プロジェクト名} .を入力して実行

エラー発生!!

 => ERROR [internal] load build context   

rpc error: code = Internal desc = stream terminated by RST_STREAM with error code: PROTOCOL_ERROR

こちらに書かれているページによると.dockerignor.dockerignor2にすると動くようです。
実際私も試してみましたが、正常に動きました。これで大丈夫なのだろうか・・

正常に動くもののもう一つエラーが出力されました

=> ERROR [builder 4/4] RUN yarn install && yarn build 

#12 65.77 error expect@29.3.1: The engine "node" is incompatible with this module. Expected version "^14.15.0 || ^16.10.0 || >=18.0.0". Got "10.24.1"

nodeのバージョンが×といわれているのでとりあえず16.10.0にしておきます。
Dockerfile↓

FROM node:16.10.0 AS builder
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