我想天真地使用这个 dockerfile。
FROM test/tomcat ENV CATALINA_HOME /tomcat RUN ${CATALINA_HOME}/bin/catalina.sh start RUN wget localhost:8080/Writer/WriterServlet
结果肯定如下
docker build --no-cache=true - < Dockerfile Sending build context to Docker daemon 3.072 kB Sending build context to Docker daemon Step 0 : FROM test/tomcat ---> 2a85ccb3dd07 Step 1 : ENV CATALINA_HOME /tomcat ---> Running in 76872d1acdd5 ---> 30ad1fe832d6 Removing intermediate container 76872d1acdd5 Step 2 : RUN ${CATALINA_HOME}/bin/catalina.sh start ---> Running in 5947560a3428 Tomcat started. ---> ea670dd1d3ff Removing intermediate container 5947560a3428 Step 3 : RUN wget localhost:8080/Writer/WriterServlet ---> Running in 6aa5c9be8569 --2014-12-19 03:08:16-- http://localhost:8080/Writer/WriterServlet Resolving localhost (localhost)... ::1, 127.0.0.1 Connecting to localhost (localhost)|::1|:8080... failed: Connection refused. Connecting to localhost (localhost)|127.0.0.1|:8080... failed: Connection refused. 2014/12/19 11:08:16 The command [/bin/sh -c wget localhost:8080/Writer/WriterServlet] returned a non-zero code: 4
在这种情况下,tomcat提供了一些接口来写文件,所以我需要通过tomcat服务器构建。
可能是因为 wget 等不及 tomcat 启动了。
或者是因为 docker 的分层容器结构导致在第 3 步(wget)时,tomcat 再次关闭。
所以我总结的问题是,我可以编写一个 docker build 来保持一些进程一起运行以满足交互式需求吗?