简体   繁体   English

无法解析 dockerfile - 没有这样的文件或目录 - docker-compose.yml

[英]Failed to resolve dockerfile - no such file or directory - docker-compose.yml

I have a project I am deploying using docker-compose.yml我有一个正在使用 docker-compose.yml 部署的项目

I current have a dockerfile in both the backend folder and frontend folder.我目前在后端文件夹和前端文件夹中都有一个 dockerfile。 I want to run both and a database.我想同时运行和一个数据库。

It is correctly building the database and fails at building the backend because of no such file or directly...它正在正确构建数据库并且由于没有这样的文件或直接...

error:错误:

(base) omarjandali@omarsMBPM1Max Fotos-React-Express % docker-compose up -d
[+] Running 12/12
 ⠿ mysqldb Pulled                                                                                                                                                                                                                                                                          10.9s
   ⠿ a2a00260331c Pull complete                                                                                                                                                                                                                                                             4.3s
   ⠿ 6d8167f2fcbe Pull complete                                                                                                                                                                                                                                                             4.3s
   ⠿ 32454e9854ca Pull complete                                                                                                                                                                                                                                                             4.4s
   ⠿ 473e2917b0d5 Pull complete                                                                                                                                                                                                                                                             4.5s
   ⠿ 5173f8104ec8 Pull complete                                                                                                                                                                                                                                                             4.6s
   ⠿ 32e218351f9a Pull complete                                                                                                                                                                                                                                                             4.6s
   ⠿ fc9e1a82359a Pull complete                                                                                                                                                                                                                                                             5.2s
   ⠿ c602a3ea2ce7 Pull complete                                                                                                                                                                                                                                                             5.2s
   ⠿ 3c9ea9927039 Pull complete                                                                                                                                                                                                                                                             8.1s
   ⠿ dfb1b236c7fc Pull complete                                                                                                                                                                                                                                                             8.2s
   ⠿ e2ad62bd72a7 Pull complete                                                                                                                                                                                                                                                             8.3s
[+] Building 0.1s (3/4)                                                                                                                                                                                                                                                                          
 => [fotos-react-express-backend internal] load build definition from Dockerfile                                                                                                                                                                                                            0.0s
 => => transferring dockerfile: 126B                                                                                                                                                                                                                                                        0.0s
 => [fotos-react-express-frontend internal] load build definition from Dockerfile                                                                                                                                                                                                           0.0s
 => => transferring dockerfile: 2B                                                                                                                                                                                                                                                          0.0s
 => [fotos-react-express-backend internal] load .dockerignore                                                                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                             0.0s
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount3723136338/Dockerfile: no such file or directory

docker-compose.yml: docker-compose.yml:

version: '3.8'

services:
  mysqldb:
    platform: linux/x86_64
    image: mysql:5.7
    restart: unless-stopped
    env_file: ./.env
    environment:
      - MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
      - MYSQL_DATABASE=$MYSQLDB_DATABASE
    ports:
      - $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
    volumes:
      - db:/var/lib/mysql
    networks:
      - backend
  
  backend:
    depends_on:
      - mysqldb
    build: ./backend
    restart: unless-stopped
    env_file: ./.env
    ports:
      - $NODE_LOCAL_PORT:$NODE_DOCKER_PORT
    environment:
      - DB_HOST=mysqldb
      - DB_USER=$MYSQLDB_USER
      - DB_PASSWORD=$MYSQLDB_ROOT_PASSWORD
      - DB_NAME=$MYSQLDB_DATABASE
      - DB_PORT=$MYSQLDB_DOCKER_PORT
      - CLIENT_ORIGIN=$CLIENT_ORIGIN
    networks:
      - backend
      - frontend

  frontend:
    depends_on:
      - backend
    build:
      context: ./frontend
      args:
        - REACT_APP_API_BASE_URL=$CLIENT_API_BASE_URL
    ports:
      - $REACT_LOCAL_PORT:$REACT_DOCKER_PORT
    networks:
      - frontend  

volumes: 
  db:

networks:
  backend:
  frontend:

the following docker file is in the backend folder以下 docker 文件位于后端文件夹中

dockerfile backend: dockerfile 后端:

FROM node:14

WORKDIR /backend
COPY package.json .
RUN npm install
COPY . .
CMD npm start

the following docker file is in the frontend folder以下 docker 文件位于前端文件夹中

dockerfile frontend: dockerfile 前端:

FROM node:14 as build-stage

WORKDIR /frontend
COPY package.json .
RUN npm install
COPY . .

ARG REACT_APP_API_BASE_URL
ENV REACT_APP_API_BASE_URL=$REACT_APP_API_BASE_URL

RUN npm run build

目录

Actually it is not failing at building the backend, it fails before that.实际上它并不是在构建后端时失败,而是在此之前失败了。

The dependency chain is:依赖链是:

  1. Frontend depends on backend.前端依赖于后端。
  2. Backend depends on the database.后端取决于数据库。
  3. The database depends on nothing.数据库不依赖于任何东西。

So, as the database depends on nothing, it is executed first and gets running.因此,由于数据库不依赖任何东西,它首先被执行并开始运行。 Now, only frontend and backend are left and both need image building, so docker-compose checks if it will be able to build both of them by looking for the files (this is where your problem is).现在,只剩下前端和后端,都需要构建图像,所以 docker-compose 检查它是否能够通过查找文件来构建它们(这就是你的问题所在)。 As last, it builds backend and then frontend.最后,它构建后端,然后构建前端。

This is where the building process starts, but it doesn't build backend and then frontend straight forward but instead docker-compose looks for the building files first:这是构建过程开始的地方,但它不会直接构建后端然后前端,而是 docker-compose 首先查找构建文件:

[+] Building 0.1s (3/4)                                                                                                                                                                                                                                                                          
 => [fotos-react-express-backend internal] load build definition from Dockerfile                                                                                                                                                                                                            0.0s
 => => transferring dockerfile: 126B                                                                                                                                                                                                                                                        0.0s
 => [fotos-react-express-frontend internal] load build definition from Dockerfile                                                                                                                                                                                                           0.0s
 => => transferring dockerfile: 2B                                                                                                                                                                                                                                                          0.0s
 => [fotos-react-express-backend internal] load .dockerignore                                                                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                             0.0s

If you read carefully, it fails when resolving the Dockerfile for the frontend.如果你仔细阅读,它会在为前端解析 Dockerfile 时失败。

failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount3723136338/Dockerfile: no such file or directory

So the problem must be with your frontend dockerfile. Check if it is called "Dockerfile" and either rename it to match exactly that name or put the following in your docker-compose.yml:所以问题一定出在你的前端 dockerfile 上。检查它是否被称为“Dockerfile”并重命名它以完全匹配该名称或将以下内容放入你的 docker-compose.yml:

build:
    context: ./frontend
    dockerfile: custom-dockerfile-name
    args:
        - REACT_APP_API_BASE_URL=$CLIENT_API_BASE_URL

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker compose is using the env which was built by Dockerfile, instead of using env_file located in docker-compose.yml directory because of webpack - Docker compose is using the env which was built by Dockerfile, instead of using env_file located in docker-compose.yml directory because of webpack 如何在不使用 Dockerfile 的情况下仅使用 Docker-compose.yml 文件启动 Node.js 应用程序的容器 - How to start the container for the Node.js application using just Docker-compose.yml file without using the Dockerfile 源代码控制(git)docker-compose.yml - Source controlling (git) docker-compose.yml .dockerignore 不忽略 docker-compose.yml - .dockerignore not ignoring docker-compose.yml docker-compose.yml问题nodejs和mysql - docker-compose.yml issue nodejs and mysql docker-compose.yml用于postgres遇到错误 - docker-compose.yml for postgres encountering error 移动 docker-compose.yml 文件时,Nginx 图像的 docker-compose 不起作用 - docker-compose of Nginx image doesn't work when the docker-compose.yml file is moved 在没有docker-compose.yml文件的单个docker文件中运行react和node - running react and node in a single docker file without docker-compose.yml file 基于 docker-compose.yml 文件的节点环境变量的切换命令 - switching command based on node env variable for the docker-compose.yml file 使用 docker-compose.yml 文件中的卷进行代码同步但无法正常工作 - Use volumes in docker-compose.yml file for code syncing but can't work properly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM