简体   繁体   English

当环境变量仅存在于容器内时,如何将环境变量传递给在 Docker 内运行的 Solr?

[英]How do you pass an environment variable to Solr running inside Docker when the environment variable only exists inside the container?

I need to do a dataimport from a PostgreSQL container running inside docker to a Solr server also running inside of Docker.我需要从在 docker 内运行的 PostgreSQL 容器到也在 ZC5FD214CDD0D2BBAC5B427 内运行的 Solr 服务器进行数据导入。

In my docker run command I specify the --link option which creates the environment variable $POSTGRESQL_PORT_5432_TCP_ADDR inside the solr docker container, and I need to pass this into Solr to use in my solrconfig.xml file. In my docker run command I specify the --link option which creates the environment variable $POSTGRESQL_PORT_5432_TCP_ADDR inside the solr docker container, and I need to pass this into Solr to use in my solrconfig.xml file.

I've heard that this is possible by passing JVM environment variables to the Solr startup command, but docker run starts Solr automatically.我听说这可以通过将 JVM 环境变量传递给 Solr 启动命令来实现,但docker run会自动启动 Z2D73204C445C889AD1。 The only workaround I've found is doing something like:我发现的唯一解决方法是执行以下操作:

docker run --name solr -d -p 8983:8983 --link postgresql --volumes-from solr_cores makuk66/docker-solr /bin/true

Starting the container with bin/true so it does nothing, and then用 bin/true 启动容器,所以它什么都不做,然后

docker exec -it solr /bin/bash

to get into the container, finally running the solr startup command myself with the flag进入容器,最后用标志自己运行 solr 启动命令

-Dsolr.database.ip=$POSTGRESQL_PORT_5432_TCP_ADDR

However this is an involved manual process, and I'm wondering if there's a better way.然而,这是一个复杂的手动过程,我想知道是否有更好的方法。

Looking on the page Taking Solr to Production you see 在查看将Solr投入生产页面上,您会看到

The bin/solr script simply passes options starting with -D on to the JVM during startup. bin / solr脚本仅在启动期间将以-D开头的选项传递给JVM。 For running in production, we recommend setting these properties in the SOLR_OPTS variable defined in the include file. 为了在生产环境中运行,建议在包含文件中定义的SOLR_OPTS变量中设置这些属性。 Keeping with our soft-commit example, in /var/solr/solr.in.sh, you would do: SOLR_OPTS="$SOLR_OPTS -Dsolr.autoSoftCommit.maxTime=10000" 与我们的软提交示例保持一致,在/var/solr/solr.in.sh中,您可以这样做:SOLR_OPTS =“ $ SOLR_OPTS -Dsolr.autoSoftCommit.maxTime = 10000”

So all you need to do is edit the SOLR_OPTS environment variable in solr.bin.sh . 因此,所有你需要做的是在编辑SOLR_OPTS环境变量solr.bin.sh

It's a bit different for Docker because you don't directly have access to solr.bin.sh , but it after some trial and error, it was as easy as adding this to my Dockerfile. 对于Docker来说有点不同,因为您没有直接访问solr.bin.sh ,但是经过反复试验后,将其添加到我的Dockerfile一样容易。

RUN echo 'SOLR_OPTS="$SOLR_OPTS -Dsolr.database.ip=$POSTGRESQL_PORT_5432_TCP_ADDR"' >> /opt/solr/bin/solr.in.sh

Then you can use it in the solrconfig.xml file as 然后,您可以在solrconfig.xml文件中将其用作

${solr.database.ip}

An important thing to note is that you can call the JVM environment variable whatever you want as long as you make sure not to overwrite anything important. 需要注意的重要一点是,只要确保不覆盖任何重要内容,就可以随意调用JVM环境变量。 I could have called it 我可以打电话给我

-Dsolr.potato

if I wanted to. 如果我想。

Great, thank you.太好了谢谢。 For some reason the solr.in.cmd file looks exactly the same as solr.in.sh which confused me on how to set variables there.由于某种原因,solr.in.cmd 文件看起来与 solr.in.sh 完全相同,这让我对如何在那里设置变量感到困惑。 In windows containers, the command to accomplish the same - from a dockerifle, would be:在 windows 容器中,完成相同操作的命令(来自 dockerif 文件)将是:

RUN Add-Content C:\solr\bin\solr.in.cmd 'set SOLR_OPTS=%SOLR_OPTS% -Dsolr.database.ip=%POSTGRESQL_PORT_5432_TCP_ADDR%' RUN 添加内容 C:\solr\bin\solr.in.cmd 'set SOLR_OPTS=%SOLR_OPTS% -Dsolr.database.ip=%POSTGRESQL_PORT_5432_TCP_ADDR%'

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

相关问题 在OS X上运行docker容器时如何将主机IP作为环境变量传递 - How to pass host IP as environment variable when running a docker container on OS X 当两者都在docker环境中启动时,如何从节点服务器连接到Postgres - How do you connect to the postgres from a node server while both is started inside a docker environment 如何将环境变量传递到.sql文件? - How do I pass an environment variable into a .sql file? 在docker容器中运行的Solr未连接到PostgreSQL数据库 - Solr running inside docker container is not connecting to PostgreSQL database 部署容器时谷歌云错误:缺少环境变量 - Google cloud error when deploying container: environment variable is missing PostgreSQL安装错误“无法写入临时环境变量路径” - PostgreSQL install error “unable to write inside temp environment variable path” 如何在金字塔ini文件中使用系统环境变量? - How can I use a system environment variable inside a pyramid ini file? Java 应用程序未在 docker 容器内应用环境变量 - Java application doesn't apply enviroment variable inside docker container 在Docker容器内运行`mkdir`时权限被拒绝 - Permission denied when running `mkdir` inside of a Docker container 如何使用 PGPASSFILE 环境变量? - How to use PGPASSFILE environment variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM