在 MERN 应用程序中找不到 Dockerfile

Dockerfile not being found in MERN application

我知道之前曾有人在这里问过这个问题,但是,我仔细阅读了他们并尝试了这些建议。我认为这是一个复杂的问题,因为每个人的文件看起来都不同,并且根据位置和路径而彼此不同,我在 Docker 中还不熟悉。现在,当我 运行 在 docker-compose build 上时,程序告诉我

Building server

Traceback (most recent call last): File "compose/cli/main.py", line 67, in main File "compose/cli/main.py", line 126, in perform_command File "compose/cli/main.py", line 302, in build File "compose/project.py", line 468, in build File "compose/project.py", line 450, in build_service File "compose/service.py", line 1147, in build compose.service.BuildError: (<Service: server>, {'message': 'Cannot locate specified Dockerfile: ./client/Dockerfile'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "docker-compose", line 3, in File "compose/cli/main.py", line 78, in main TypeError: can only concatenate str (not "dict") to str [34923] Failed to execute script docker-compose

我已经尝试将 Docker 文件从客户端放置到与 docker-compose.yml 文件相同的目录以消除路径差异,但是,它仍然说同样的话.如果您有任何建议,请告诉我。谢谢!

这是我的 docker-compose.yml 文件

version: "3.7"

services:
  server:
    build:
      context: ./server
      dockerfile: ./client/Dockerfile
    image: myapp-server
    container_name: myapp-node-server
    command: /usr/src/app/node_modules/.bin/nodemon server.js
    volumes:
      - ./server/:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - "5050:5050"
    depends_on:
      - mongo
    env_file: ./server/.env
    environment:
      - NODE_ENV=development
    networks:
      - app-network
  mongo:
    image: mongo
    volumes:
      - data-volume:/data/db
    ports:
      - "27017:27017"
    networks:
      - app-network
  client:
    build:
      context: ./client
      dockerfile: Dockerfile
    image: myapp-client
    container_name: myapp-react-client
    command: npm start
    volumes:
      - ./client/:/usr/app
      - /usr/app/node_modules
    depends_on:
      - server
    ports:
      - "3000:3000"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  data-volume:
  node_modules:
  web-root:
    driver: local

这是客户端文件夹中的Docker文件

FROM node:10.16-alpine

WORKDIR /usr/src/app

COPY package.json ./

RUN npm install 

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

这是服务器文件夹中的Docker文件

FROM node:10.16-alpine

# Create App Directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install Dependencies
COPY package*.json ./

RUN npm install --silent

# Copy app source code
COPY . .

# Exports
EXPOSE 5050

CMD ["npm","start"]

编辑 1:问题是 dockerfiles 的路径不寻常:client/docker-mern-basic。您可以在客户端路径的 VSCode 文件资源管理器中看到这一点。通过使路径和 context/dockerfile 路径一致,消除额外的 docker-mern-basic 路径来解决。请参阅下面的评论。

编辑 0:这不能解决问题,如果我找不到任何其他可能的问题,我将删除它。

server.build.dockerfile 的路径与您的上下文无关。您正在提供用作“root”的文件夹 server 所以 Docker 实际上是在寻找路径 ./server/client/Dockerfile.

我认为您的问题没有给出与您的上下文相关的路径:

services:
  server:
    build:
      context: ./server
      dockerfile: Dockerfile