在运行容器时成功使用curl

时间:2017-04-11 08:23:06

标签: curl docker dockerfile marklogic

我尝试使用Docker构建并运行Marklogic实例。 Marklogic提供了一些不错的http api,因此,作为Dockerfile中的最终> log [07:54:06.223] [error][status][plugin:xpack_main@5.1.1] Status > changed from yellow to red – Authorization Exception log > [07:54:06.224] [error][status][plugin:graph@5.1.1] Status changed from > yellow to red – Authorization Exception log [07:54:06.224] > [error][status][plugin:reporting@5.1.1] Status changed from yellow to > red – Authorization Exception log [07:54:06.225] > [error][status][plugin:elasticsearch@5.1.1] Status changed from yellow > to red – Authorization Exception log [07:54:06.230] > [error][status][plugin:security@5.1.1] Status changed from > uninitialized to red – Authorization Exception log [07:54:06.231] > [warning][security] Generating a random key for > xpack.security.encryptionKey. To prevent sessions from being > invalidated on restart, please set xpack.security.encryptionKey in > kibana.yml log [07:54:06.234] [warning][security] Session cookies will > be transmitted over insecure connections. This is not recommended. log > [07:54:06.279] [error][status][plugin:profiler@5.1.1] Status changed > from uninitialized to red – Authorization Exception ,我运行了两个脚本,他们通过CMD执行一些http请求,以便在容器启动时正确配置Marklogic的实例。但是当我运行我的图像时,

curl

我收到了这个错误:

docker run -p 7997-8002:7997-8002 --name gi-ml-container -e USER=admin -e PASSWORD=admin -e REALM=public -e HOST=gi-ml-container gi-marklogic

我认为应该使用conainer的名字。如何对Dockerfile运行的容器0curl: (6) Could not resolve host: gi-ml-container; Name or service not known 进行操作?这是正确的方法吗? 我正在使用Docker 1.12.6,在Ubuntu 16.04上构建78d1802。这是我的Dockerfile:

curl

此Dockerfile使用两个FROM centos:centos7 ARG USER=admin ARG PASSWORD=admin ARG REALM=public ARG HOST=localhost RUN yum -y install glibc.i686 gdb.x86_64 redhat-lsb.x86_64 && yum clean all RUN yum -y install initscripts && yum clean all ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/MarkLogic/mlcmd/bin COPY MarkLogic-RHEL7-8.0-6.3.x86_64.rpm /tmp/MarkLogic-RHEL7-8.0-6.3.x86_64.rpm COPY marklogic.admin.setup.sh /tmp/marklogic.admin.setup.sh COPY marklogic.init.database.sh /tmp/marklogic.init.database.sh RUN chmod +x /tmp/*.sh RUN yum -y install /tmp/MarkLogic-RHEL7-8.0-6.3.x86_64.rpm RUN rm /tmp/MarkLogic-RHEL7-8.0-6.3.x86_64.rpm EXPOSE 7997 7998 7999 8000 8001 8002 CMD /etc/init.d/MarkLogic start && ./tmp/marklogic.init.database.sh -h $HOST && ./tmp/marklogic.admin.setup.sh -u $USER -p $PASSWORD -r $REALM -h $HOST && tail -f /dev/null 文件将Marklogic实例配置为容器启动。这是.sh

marklogic.init.database.sh

这是我的TIMESTAMP=`curl -d "" -X POST http://${HOST}:8001/admin/v1/init`

marklogic.admin.setup.sh

我很好地跟进了Maklogic在一些关于如何执行此操作herehere的好文章中的内容。

1 个答案:

答案 0 :(得分:1)

少数事情:

1)您必须在-h中使用docker run选项指定主机名:-h gi-ml-container-d

docker run -p 7997-8002:7997-8002 --name gi-ml-container -e USER=admin -e PASSWORD=admin -e REALM=public -e HOST=gi-ml-container-d -h gi-ml-container-d gi-marklogic

因此,您可以在不使用$HOST的情况下更改Dockerfile和脚本,但只需将-h添加到docker run即可。

2)当您将MarkLogic作为服务启动时,它会过快地返回控件,因此在下一个命令运行时它还没有运行。所以加一个睡眠来推迟它:

CMD /etc/init.d/MarkLogic start && sleep 5 && /tmp/marklogic.init.database.sh -h $HOST && sleep 5 && /tmp/marklogic.admin.setup.sh -u $USER -p $PASSWORD -r $REALM -h $HOST && tail -f /dev/null

3)在marklogic.admin.setup.sh脚本中,确保$CURL不为空。也许你可以直接在其中写curl。另外(可能已经是正确的,它只是一个复制和粘贴问题)请确保"Content type..."-X POST -H位于同一行(或者将其与\连接,就像您在以下几行)

TIMESTAMP=`curl -X POST -H "Content-type: application/x-www-form-urlencoded" \
--data "admin-username=${USER}" --data "admin-password=${PASS}" \
--data "realm=${SEC_REALM}" \
http://${HOST}:8001/admin/v1/instance-admin`

4)最后,尽管它不应该有任何影响,因为你在/tmp中使用脚本的绝对路径名,你不需要在它们之前加.(所以./tmp/marklogic.init.database.sh不是/tmp/marklogic.init.database.sh 1}}但是<server name="default-server"> <host name="default-host" alias="localhost"> <filter-ref name="cache-control" predicate="path-suffix['.html'] or path-suffix['.jsf'] or path-suffix['.xhtml'] or path-suffix['.css'] or path-suffix['.js']"/> </host> </server> <filters> <response-header name="cache-control" header-name="Cache-Control" header-value="no-cache"/> </filters> 就足够了,它不依赖于您的工作目录。