Docker安装发生在入口点执行之前或之后 [英] Docker mount happens before or after entrypoint execution

查看:59
本文介绍了Docker安装发生在入口点执行之前或之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Docker映像以运行基于Spring Boot的应用程序.我希望用户能够通过将包含application.properties的文件夹装入容器来提供运行时属性文件.这是我的Dockerfile,

I'm building a Docker image to run my Spring Boot based application. I want to have user to be able to feed a run time properties file by mounting the folder containing application.properties into container. Here is my Dockerfile,

FROM java:8

RUN mkdir /app
RUN mkdir /app/config
ADD myapp.jar /app/

ENTRYPOINT ["java","-jar","/app/myapp.jar"]

启动容器时,我会运行

docker run -d -v /home/user/config:/app/config myapp:latest

其中/home/user/config 包含 application.properties ,我希望jar文件在运行时拾取.

where /home/user/config contains the application.properties I want the jar file to pick up during run time.

但是,这不起作用,应用程序运行不会拾取此已挂载的属性文件,它使用的是jar中包装的默认文件.但是,当我 exec 进入启动的容器并再次手动运行entrypoint cmd时,通过拾取我安装的文件,它可以按预期工作.入口点?还是在这种情况下我没有正确编写Dockerfile?

However this doesn't work, the app run doesn't pick up this mounted properties file, it's using the default one packed inside the jar. But when I exec into the started container and manually run the entrypoint cmd again, it works as expected by picking up the file I mounted in. So I'm wondering is this something related to how mount works with entrypoint? Or I just didn't write the Dockerfile correctly for this case?

推荐答案

Spring Boot

Spring Boot searches for application.properties inside a /config subdirectory of the current directory (among other locations). In your case, current directory is / (docker default), so you need to change it to /app. To do that, add

WORKDIR /app

ENTRYPOINT 行之前.

并回答您最初的问题:在容器中的任何东西运行之前完成挂载.

And to answer your original question: mounts are done before anything inside the container is run.

这篇关于Docker安装发生在入口点执行之前或之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆