当我构建镜像并运行时,我不断收到此消息
❌❌❌
(节点:26)[DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning:“onAfterSetupMiddleware”选项已弃用。 请使用“setupMiddlewares”选项。 (使用
显示创建警告的位置)(节点:26)[DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning:“onBeforeSetupMiddleware”选项已弃用。 请使用“setupMiddlewares”选项。开始开发 服务器...node --trace-deprecation ...
➜ ace git:(main) ✗ docker build -t ace-image .
[+] Building 9.7s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 625B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/node:16-alpine 0.5s
=> [1/6] FROM docker.io/library/node:16-alpine@sha256:b4a72f83f52bbe3970bb74a15e44ec4cf6e873ad4787473dfc8a26f5b4e29 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 24.22kB 0.1s
=> CACHED [2/6] WORKDIR /app 0.0s
=> CACHED [3/6] COPY package*.json ./ 0.0s
=> CACHED [4/6] RUN npm install --quiet 0.0s
=> [5/6] COPY . . 0.0s
=> [6/6] RUN npm run build 8.9s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:478016d17cf8826bbbb94faecc2a4f556a5f77280c41342bd27b1b200f2870ba 0.0s
=> => naming to docker.io/library/ace-image 0.0s
➜ ace git:(main) ✗ docker run -p 3000:3000 ace-image
> [email protected] start
> react-scripts start --quiet
(node:26) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:26) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...
Compiled successfully!
You can now view ace in the browser.
Local: http://localhost:3000
On Your Network: http://172.17.0.2:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
webpack compiled successfully
Compiling...
Compiled successfully!
webpack compiled successfully
如您所见,我已经尝试将其静音,但没有用
我试过了
CMD ["npm", "start", "--", "--quiet"]
# Set the base image to Node 16
FROM node:16-alpine
# Set the working directory in the container to /app
WORKDIR /app
# Copy the package.json and package-lock.json files to the container
COPY package*.json ./
# Install dependencies quietly
RUN npm install --quiet
# Copy the rest of the application code to the container
COPY . .
# Build the application
RUN npm run build
# Expose port 3000
EXPOSE 3000
# Run the command to start the server
CMD ["npm", "start", "--", "--quiet"]
使用--不弃用:
# Dockerfile
CMD ["npm", "start"]
// package.json
"scripts": {
"start": "node --no-deprecation [entrypoint e.g. index.js]",
...
您可能想要使用此标志添加一个新脚本,例如
start:production
,这样您仍然可以在开发过程中看到警告。
使用
npm run build
构建您的应用程序后,您不再需要使用 start
命令来启动开发服务器。您可以改为定义多阶段 Docker 构建以使用 nginx 为您的应用程序提供服务。
A
Dockerfile
这样应该有帮助:
# Stage 1: Compile and build the app
# Set the build stage image to Node 16
FROM node:16-alpine as build
# Set the working directory in the container to /app
WORKDIR /app
# Copy the package.json and package-lock.json files to the container
COPY package*.json ./
# Install dependencies quietly
RUN npm install --quiet
# Copy the rest of the application code to the container
COPY . .
# Build the application
RUN npm run build
# Stage 2: Serve app with nginx
# Set the base running image to nginx Alpine
FROM nginx:alpine-perl
# Copy the output from the build stage
COPY --from=build /app/dist/my-app /usr/share/nginx/html
# Expose port 80
EXPOSE 80
您需要将 /app/dist/my-app 更改为您的应用程序名称。
正如您在
Dockerfile
中所见,没有定义自定义CMD
命令。默认情况下,nginx 镜像将提供 /usr/share/nginx/html
的内容。