简体   繁体   English

docker镜像可以使用来自主机的可执行文件吗?

[英]Can a docker image use executable from the host?

I have several Java services, each packaged as a separate jar file. 我有几个Java服务,每个服务打包为一个单独的jar文件。 I plan to package the as docker images. 我计划将其打包为docker图像。 Do I need to bundle the Java runtime on each image, or can I rely on the fact the host (that will run the image) already has the Java runtime? 我是否需要在每个映像上捆绑Java运行时,或者我可以依赖主机(将运行映像)已经具有Java运行时的事实?

You could use a volume to mount the Java runtime from the host into the container, but this makes the container less portable (as Andrew Fox points out). 您可以使用卷将Java运行时从主机安装到容器中,但这会使容器的可移植性降低(正如Andrew Fox指出的那样)。

If instead you use a common base image such as java:8-jre for your containers, the image will be shared between containers meaning that there is only one copy on disk (not one copy per container). 相反,如果您为容器使用公共基本映像(如java:8-jre ,则映像将在容器之间共享,这意味着磁盘上只有一个副本(每个容器不是一个副本)。

Not that in both cases, you will still have multiple JVMs running, one for each container. 在这两种情况下,您仍然可以运行多个JVM,每个容器一个。

The idea of docker is to make your setup portable so if you don't put in the Java runtime you can't guarantee it will work properly on a destination system. docker的想法是使您的设置可移植,因此如果您不放入Java运行时,则无法保证它在目标系统上正常工作。 I don't believe docker can access host executables unless there is a special whitelist setting somewhere but in my experience no it can't. 我不相信docker可以访问主机可执行文件,除非在某处有特殊的白名单设置,但根据我的经验,它不能。

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

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