0

上下文: 我已经为在 AWS 上运行的 React 应用程序设置了基本代码。我添加了身份验证和 Graphql 工具。基本上,我完成了本教程中指定的所有内容:https ://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/ 。

我想 Dockerize 我的应用程序并根据本教程添加了 Dockerfile、Dockerfile.dev 和 docker-compose.yml 文件:https ://medium.com/better-programming/heres-how-you-can-use-docker -with-create-react-app-3ee3a972b04e。我将把我的 Dockerfiles 的内容放在这篇文章的底部。

问题: 我在包含我的 React 应用程序的目录中并运行了docker-compose up命令,但我收到了很多警告,我将把它们放在本段下方。正如我在 docker-compose.yml 中指定的那样,我的应用程序在端口 3000 上成功运行。我的问题是我是否错过了 Dockerfiles 中导致 Docker 抛出所有这些警告的关键代码。我已经将 Docker 用于我在实习期间成功构建的 React 应用程序,但我不确定如果我在 AWS 上运行我的 React 应用程序是否需要添加任何额外的东西。如果有人有任何建议,将不胜感激。如果我在帖子中遗漏了关键信息,请告诉我,并原谅我,因为我对使用 Docker 还是很陌生。

Dockerfile

FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
CMD ["npm", "start"]

Dockerfile.dev

FROM node:alpine
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["npm", "run", "start"]

码头工人-compose.yml

version: "3.8"
services:
    client:
        stdin_open: true
        build:
            context: .
            dockerfile: Dockerfile.dev
        ports:
            - "3000:3000"
        volumes:
            - "/app/node_modules"
            - "./:/app"

码头工人终端警告

Step 4/6 : RUN npm install
 ---> Running in e245d3bb0bc3
npm WARN deprecated eslint-loader@3.0.3: This loader has been deprecated. Please use eslint-webpack-plugin
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated @types/testing-library__dom@7.5.0: This is a stub types definition. testing-library__dom provides its own type definitions, so you do not need this installed.
npm WARN deprecated request@2.88.2: request has been deprecated, see 

https://github.com/request/request/issues/3142
npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/joi@15.1.1: joi is leaving the @hapi organization and moving back to 'joi' (https://github.com/sideway/joi/issues/2411)
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated buffer@4.9.1: This version of 'buffer' is out-of-date. You must update to v4.9.2 or newer
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated @hapi/address@2.1.4: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
...
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/react-scripts/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"14.13.1","npm":"6.14.8"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN react-native-get-random-values@1.5.0 requires a peer of react-native@>=0.56 but none is installed. You must install peer dependencies yourself.
npm WARN @aws-amplify/datastore@2.6.0 requires a peer of @react-native-community/netinfo@^5.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer 
dependencies yourself.

added 1825 packages from 1181 contributors and audited 1829 packages in 53.175s
4

1 回答 1

1

这些警告与添加到 Docker.dev 文件中的 Docker 映像的 npm 包有关,步骤 4 - npm install,实际上并不是 docker 警告。

无论是否容器化,这些包都是 react 应用程序的一部分,因此警告也会显示是否npm install从本地终端运行。

如果您希望隐藏警告,添加--silent(或者使用-sor --no-warnings),就像您在步骤 6 中的 Dockerfile 中所拥有的一样,将隐藏这些警告。

于 2020-11-26T03:59:31.603 回答