gpt4 book ai didi

docker - 在docker-compose中使用入口点运行自定义脚本

转载 作者:行者123 更新时间:2023-12-05 00:50:53 30 4
gpt4 key购买 nike

通过添加docker-compose.yml配置和volumes的更改,我修改了https://hub.docker.com/_/solr/上给出的entrypoint文件。修改后的文件如下:

version: '3'
services:
solr:
image: solr
ports:
- "8983:8983"
volumes:
- ./solr/init.sh:/init.sh
- ./solr/data:/opt/solr/server/solr/mycores
entrypoint:
- init.sh
- docker-entrypoint.sh
- solr-precreate
- mycore

我需要在入口点启动之前运行此“init.sh”,以在容器中准备我的文件。

但是我收到以下错误:

ERROR: for solr_solr_1 Cannot start service solr: oci runtime error: container_linux.go:247: starting container process caused "exec: \"init.sh\": executable file not found in $PATH"



早些时候,我从 here中发现了neo4j中的官方图像 Hook 。我在这里也可以使用类似的东西吗?

更新1:从下面的注释中,我意识到dockerfile设置了 WORKDIR /opt/solr,这是因为 executable file not found in $PATH。因此,我通过使用 /init.sh提供了指向入口点的绝对路径进行了测试。但这也带来了错误,但是却有所不同:

standard_init_linux.go:178: exec user process caused "exec format error"

最佳答案

看来您需要将卷映射到/docker-entrypoint-initdb.d/

version: '3'
services:
solr:
image: solr
ports:
- "8983:8983"
volumes:
- ./solr/init.sh:/docker-entrypoint-initdb.d/init.sh
- ./solr/data:/opt/solr/server/solr/mycores
entrypoint:
- docker-entrypoint.sh
- init



https://hub.docker.com/_/solr/

Extending the image The docker-solr image has an extension mechanism. At run time, before starting Solr, the container will execute scripts in the /docker-entrypoint-initdb.d/ directory. You can add your own scripts there either by using mounted volumes or by using a custom Dockerfile. These scripts can for example copy a core directory with pre-loaded data for continuous integration testing, or modify the Solr configuration.



docker-entrypoint.sh似乎负责根据传递给它的参数来运行sh脚本。因此,init是第一个尝试运行init.sh的参数。
docker-compose logs solr | head

更新1:

我一直在努力使其工作,最后弄清楚了为什么在指向/docker-entrypoint-initdb.d/init.sh的 docker run -v工作时我的docker-compose无法工作。

事实证明,删除入口点树是解决方案。这是我最后的docker-compose:
version: '3'
services:
solr:
image: solr:6.6-alpine
ports:
- "8983:8983"
volumes:
- ./solr/data/:/opt/solr/server/solr/
- ./solr/config/init.sh:/docker-entrypoint-initdb.d/init.sh

我的./solr/config/init.sh
#!/bin/bash
echo "running"
touch /opt/solr/server/solr/test.txt;
echo "test" > /opt/solr/server/solr/test.txt;

关于docker - 在docker-compose中使用入口点运行自定义脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45211594/

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