简体   繁体   English

Docker 编写“错误:找不到文件”,但 ubuntu shell 可以找到该文件

[英]Docker Compose “ERROR: file not found”, but ubuntu shell can find the file

I'm trying to get a Docker Compose script to test a python program.我正在尝试获取 Docker Compose 脚本来测试 python 程序。 The following is the.sh to run the docker-compose command.下面是运行docker-compose命令的.sh。

#!/usr/bin/env bash

script_path=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
base_path=${script_path}/src

container_path=${base_path}/deploy/
docker_compose_path=${container_path}docker-compose.yml

sudo nano ${base_path}/tests/scrap/test_r.py

docker-compose -f "${docker_compose_path}" run service_name pytest -x ${base_path}/tests/scrap/test_r.py
docker-compose -f "${docker_compose_path}" down

The problem when running it is that an error shows up with the following message:运行时的问题是出现错误并显示以下消息:

ERROR: file not found: /correct/path/to/test_r.py

NOTE: I have checked many times and the path (absolute) is correct.注意:我检查了很多次,路径(绝对)是正确的。

The odd thing about the error is that the shell can find it with no problem.该错误的奇怪之处在于 shell 可以毫无问题地找到它。 The nano command that is right on top of the docker-compose one works perfectly, loading the file with the correct content.位于 docker-compose 顶部的 nano 命令完美运行,加载具有正确内容的文件。 Still, with the same exact path, docker-compose seems to not be able to find it and execute it (already tried chmod +x test_r.py but it did not work. Docker Compose simply doesn't find it).尽管如此,使用相同的确切路径,docker-compose 似乎无法找到它并执行它(已经尝试 chmod +x test_r.py 但它不起作用。Docker Compose 根本找不到它)。

Whatever extra info that you need, you can ask.无论您需要什么额外的信息,您都可以询问。 Thanks:P谢谢:P

NOTE: I'm not considering as a source of the problem the fact that the project worked perfectly on another computer that was running MacOS.注意:我不认为该项目在另一台运行 MacOS 的计算机上完美运行的事实是问题的根源。 My pc is trying to execute the scripts in an Ubuntu environment.我的电脑正在尝试在 Ubuntu 环境中执行脚本。 If taking that into account is a step in the right direction, I don't know how to move toward solving the issue.如果考虑到这一点是朝着正确方向迈出的一步,我不知道如何解决这个问题。

Edit: adding info of the file docker-compose.yml:编辑:添加文件 docker-compose.yml 的信息:

version: '3.5'

services:
  service_name:
    image: image_name
    build:
      context: ../
      dockerfile: Dockerfile
    tty: true
    volumes:
      - ../../../workers:/opt/workers/
    working_dir: /opt/workers/src
    env_file:
      - ../local/worker.env

Turns out all I had to do was update the "working_dir" path in the docker-compose.yml file to make it find the corresponding py file.原来我所要做的就是更新 docker-compose.yml 文件中的“working_dir”路径,以使其找到相应的 py 文件。 The problem was that I had no idea that I had to pay attention to that info.问题是我不知道我必须注意这些信息。 Thanks to @David Maze for asking me all of the questions.感谢@David Maze 问了我所有的问题。 Sometimes asking the right ones points on in the right direction.有时问对的人指向正确的方向。

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

相关问题 FastAPI docker-compose文件未找到错误 - FastAPI docker-compose File Not Found Error Docker compose - 找不到 manage.py 文件 - Docker compose - can't find manage.py file C:\\Users\\krish\\Desktop\\code\\hello> docker-compose up can't find a合适的配置文件在这个目录或任何父目录: not found - C:\Users\krish\Desktop\code\hello> docker-compose up can't find a suitable configuration file in this directory or any parent: not found 在 $PATH 中找不到 Docker 撰写可执行文件”:未知 - Docker compose executable file not found in $PATH": unknown 在docker compose yml文件中设置环境变量时找不到文件错误 - file not found error when setting the environment variable in docker compose yml file Docker 组成给出错误没有这样的文件或目录。 ubuntu 中的 for.sh 文件 - Docker compose up giving error no such file or dir. for .sh files in ubuntu docker-compose 在创建 docker 镜像时找不到文件 - docker-compose can't find file while creating docker image 如何在 docker-compose 之后在 shell 脚本中运行 python 文件? - How to run python file after docker-compose in a shell script? docker-compose 错误:Windows 上的“没有这样的文件或目录” - docker-compose error: "no such file or directory" on Windows docker-compose exec: \“webserver\”: $PATH 中找不到可执行文件 - docker-compose exec: \“webserver\”: executable file not found in $PATH
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM