[英]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.