gpt4 book ai didi

docker - Docker-compose:exec用户进程导致 “no such file or directory”但文件存在

转载 作者:行者123 更新时间:2023-12-02 20:47:07 32 4
gpt4 key购买 nike

使用以下docker-compose.yml文件,我创建一个包含两个服务的堆栈:一个是Web应用程序(称为Broker),另一个是Web应用程序使用的MySQL数据库(称为broker_db)。

我发现我必须告诉代理服务等待MySQL初始化,并且我可以使用一个Shell脚本来延迟代理真正启动Web应用程序的时间,直到它可以开始使用数据库为止。但是,在运行docker-compose up时出现以下错误:

 broker_1     | standard_init_linux.go:190: exec user process caused "no such file or directory"

我的 docker-compose.yml文件是:
version: '3'

services:
broker-db:
image: mysql:5.7 # https://store.docker.com/images/mysql
restart: always
environment:
MYSQL_DATABASE: broker # Create a database with name broker during container initialization.
MYSQL_ROOT_PASSWORD: root # Set root/root as user/password credentials in the container.
ports:
- "3302:3306"
volumes:
- ./broker-db-volume:/var/lib/mysql
networks:
- shared-network

broker:
build: .
command: ["/code/wait-for-mysql-init.sh", "broker-db", "python3", "manage.py", "runserver", "0.0.0.0:8080"]
volumes:
- .:/code
ports:
- "8080:8080"
depends_on:
- broker-db
restart: always
networks:
- shared-network

networks:
shared-network:

代理的Dockerfile将其根项目文件夹中的所有代码添加到Docker容器中的 /code中,所以我不明白为什么 docker-compose up表示找不到 wait-for-mysql-init.sh:
# Based on https://docs.docker.com/compose/django
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
RUN chmod +x wait-for-mysql-init.sh

Shell脚本如下:
#!/bin/bash
# wait-for-mysql-init.sh

# Taken from https://stackoverflow.com/a/29793382/5433896.
# Argument handling based on https://unix.stackexchange.com/questions/31414.
# Delayed command execution based on https://docs.docker.com/compose/startup-order/.

set -e # Exit immediately if a command exits with a non-zero status (https://stackoverflow.com/a/19622569/5433896).

DB_HOST="$1" # First argument passed to the script
shift # Forget the first argument, $2 becomes $1, $3 becomes $2 and so on.
command="$@" # All remaining arguments form the command to execute after MySQL is initialized.

while ! mysqladmin ping -h"$DB_HOST" --silent; do
echo "The initialization of MySQL on $DB_HOST is still ongoing."
sleep 1
done

echo "The initialization of MySQL on $DB_HOST has finished. It is ready to accept incoming queries."
echo "MySQL is up and running. Executing command $command."
exec $command

另外,我的经纪人项目内容的简要概述:
C:\*somepath*\broker
├───broker-application-code
├───broker-db-volume
├───broker
├───.dockerignore
├───docker-compose.yml
├───Dockerfile
├───manage.py
├───requirements.txt
└───wait-for-mysql-init.sh

因此,肯定存在用于添加到Docker镜像的Shell脚本,ADD指令位于Dockerfile中,为什么在启动代理容器时仍找不到Shell脚本?

最佳答案

对于 shell 程序脚本,找不到可执行文件意味着脚本本身不存在,或者脚本在第一行启动的 shell 程序不存在。要寻找的东西:

  • 图片中是否存在/ bin / bash?因为python 3.6是基于Debian的,所以应该这样。
  • 是容器内的卷装载覆盖目录吗? .:/code卷挂载意味着您​​在该位置的镜像中执行的所有操作都将被替换,但是您似乎正在同一目录中运行。
  • 是该脚本确实试图运行/bin/bash,还是该文件中有Windows换行符? Linux不了解Windows的换行符,因此它将查找要执行的/bin/bash^M,该代码不存在。
  • 关于docker - Docker-compose:exec用户进程导致 “no such file or directory”但文件存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50757368/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com