使用以下docker-compose.yml
文件,我创建一个包含两个服务的堆栈:一个是Web应用程序(称为 broker ),另一个是MySQL数据库(称为 broker_db) )Web应用程序使用的。
我发现我必须告诉代理服务要等到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
:< / p>
# 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
因此shell脚本肯定存在于添加到docker镜像中,ADD指令在Dockerfile中,为什么在启动代理容器时仍然找不到shell脚本?
答案 0 :(得分:3)
使用shell脚本,找不到可执行文件意味着脚本本身不存在,或者脚本在第一行上启动的shell不存在。需要注意的事项:
.:/code
卷装置意味着您在该位置的图像中执行的所有操作都将被替换,但您似乎是从同一目录运行。/bin/bash
的脚本,还是文件中有Windows换行符? Linux不了解Windows换行符,因此它会查找要执行的/bin/bash^M
,而不存在。答案 1 :(得分:-1)
尝试from pathlib import Path
def saveJSONget(site, code):
r = requests.get(site)
json_str = r.text
if r.status_code != code:
Path("PATH").write_text(r.text+"\n")
而不是$.ajax({
url: "url",
type : "POST",
async: false,
contentType: "application/json",
//dataType: "json",
data : { firstDate : monday,
secondDate : lastday}
//student_name : $('#id_student_name').val()
}).then(function(data) {
var obj = JSON.parse(data);
for (var a = 0; a < obj.results.length; a++) {
res[a] = obj.results[a];
dates.push(obj.results[a].DATESTART);
}
console.log(res);
});
COPY