简体   繁体   English

Docker 多级不调用入口点

[英]Docker multistage doesn't call entrypoint

I have a grails app running in Docker, and I was trying to add the Apache Derby server to run in the same image using Docker multi stage. I have a grails app running in Docker, and I was trying to add the Apache Derby server to run in the same image using Docker multi stage. But when I add Derby, then the grails app doesn't run.但是当我添加 Derby 时,grails 应用程序无法运行。

So I started with this:所以我从这个开始:

$ cat build/docker/Dockerfile
FROM azul/zulu-openjdk:13.0.3
EXPOSE 8080
VOLUME ["/AppData/derby"]
WORKDIR /app
COPY holder-0.1.jar application.jar
COPY app-entrypoint.sh app-entrypoint.sh
RUN chmod +x app-entrypoint.sh
RUN apt-get update && apt-get install -y dos2unix && dos2unix app-entrypoint.sh
ENTRYPOINT ["/app/app-entrypoint.sh"]

So far, so good this starts off grails as a web server, and I can connect to the web app.到目前为止,一切顺利,从 grails 作为 web 服务器开始,我可以连接到 web 应用程序。 But then I added Derby....但后来我加了德比......

FROM azul/zulu-openjdk:13.0.3
EXPOSE 8080
VOLUME ["/AppData/derby"]
WORKDIR /app
COPY holder-0.1.jar application.jar
COPY app-entrypoint.sh app-entrypoint.sh
RUN chmod +x app-entrypoint.sh
RUN apt-get update && apt-get install -y dos2unix && dos2unix app-entrypoint.sh
ENTRYPOINT ["/app/app-entrypoint.sh"]
FROM datagrip/derby-server
WORKDIR /derby

Now when I start the container, Derby runs, but the grails app doesn't run at all.现在,当我启动容器时,Derby 运行,但 grails 应用程序根本不运行。 This is obvious from what is printed on the terminal, but I also logged in and did a ps aux to verify it.从终端上打印的内容可以看出这一点,但我也登录并执行了ps aux来验证它。

Now I suppose I could look into creating my own startup script to start the Derby server, although this would seem to violate the independence of the two images' configurations.现在我想我可以考虑创建自己的启动脚本来启动 Derby 服务器,尽管这似乎违反了两个映像配置的独立性。

Other people might say, I should use two containers, but I was hoping to keep it simple, derby is a very simple database, I don't feel the need for this complexity here.其他人可能会说,我应该使用两个容器,但我希望保持简单,derby 是一个非常简单的数据库,我觉得这里不需要这种复杂性。

Am I just trying to push the concept of multi stage docker containers too far?我只是想将多级 docker 容器的概念推得太远吗?

Is it actually normal at all for docker containers to have more than one process start up? docker 容器启动多个进程实际上是否正常? Will I have to fudge it and come up with my own entry point that starts Derby server in the background before starting grails in the foreground?在前台启动 grails 之前,我是否必须捏造它并提出自己的入口点,在后台启动 Derby 服务器? Or is this all just wrong, and I really should be using multiple containers?或者这一切都是错的,我真的应该使用多个容器?

It is fine for Docker to have multiple processes in one container but the concept is different: one container, one process. Docker 可以在一个容器中有多个进程,但概念不同:一个容器,一个进程。 Having a database separately is certainly how it should be done.单独拥有一个数据库当然是应该这样做的。

Now the problem with your Dockerfile is that after you've declared a second FROM , you have effectively discarded most of what you've done so far.现在,您的 Dockerfile 的问题在于,在您声明了第二个FROM之后,您实际上已经放弃了迄今为止所做的大部分工作。 You may use a previous stage to copy some files from it (this is normally used to build some binaries) but Docker will not do that for you, unless you explicitly define what to copy.您可以使用前一个阶段从中复制一些文件(这通常用于构建一些二进制文件),但 Docker 不会为您执行此操作,除非您明确定义要复制的内容。 Thus your actual entrypoint is the one declared in datagrip/derby-server image.因此,您的实际入口点是在datagrip/derby-server映像中声明的入口点。

I suggest you get started with docker-compose .我建议您开始使用docker-compose It's a nice tool to run several containers without complications.这是一个很好的工具,可以轻松运行多个容器。 With a file like this:使用这样的文件:

version: "3.0"
services:
  app:
    build:
      context: .

  database:
    image: datagrip/derby-server

docker-compose will build an image for the app (if the Dockefile is in the same directory but this can be customised) and start a database as well. docker-compose 将为应用程序构建一个映像(如果 Dockefile 在同一目录中但可以自定义)并启动一个数据库。 The database can be access from the application container as just 'database' (it is a resolvable name).可以从应用程序容器中访问数据库,就像“数据库”一样(它是一个可解析的名称)。 See this reference for more options.有关更多选项,请参阅 此参考

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM