如何使用文件路径URL引用嵌入式Docker资源文件 [英] How to reference embedded Docker resource files using file path URL

查看:370
本文介绍了如何使用文件路径URL引用嵌入式Docker资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Docker映像并在Dockerfile中使用以下命令嵌入了一些静态资源文件:

I have created a Docker image and embedded some static resource files within it, using the following command in the Dockerfile:

COPY resources /resources

我在Docker容器中运行了一个Java Web应用程序,该应用程序需要访问这些静态文件.必须使用URL提供文件路径,例如:

I have a java web application running within the Docker container which requires access to these static files. File paths must be provided using a URL, E.g.:

file://c:/resources/myresourcefile.css

我能够以编程方式构造URL,但是不确定是否可以以这种方式引用嵌入式文件.任何指导将不胜感激!

I am able to construct the URL programmatically but am unsure if embedded files can be referenced this way. Any guidance would be appreciated!

注意:我专门使用pdfreactor Web服务,因此我的Dockerfile是:

Note: I am specifically using the pdfreactor web service, and my Dockerfile is thus:

FROM realobjects/pdfreactor:9.1
EXPOSE 9423
COPY resources /resources

我正在尝试将PDFreactor包装器客户端的"BaseURL"设置为根资源文件夹.

I am trying to set the "BaseURL" of the PDFreactor wrapper client to the root resource folder.

推荐答案

如果它是Linux容器,并且请求者是您在容器中运行的Java进程,那么file:///resources会指向您添加的目录(子目录图片根目录的名称).如果将URL提供给容器外部的某个内容(例如HTML链接或图像引用),则file: URL将无法访问容器内部的文件;您将不得不想出其他方法来提供文件并为它们提供HTTP URL.

If it’s a Linux container, and the requestor is specifically your Java process running inside the container, then file:///resources will point at the directory you added (a subdirectory of the image root directory). If the URL is being served to something outside the container (like an HTML link or image reference) then a file: URL won’t be able to access files inside the container; you’d have to come up with something else to serve up the files and provide an HTTP URL to them.

这篇关于如何使用文件路径URL引用嵌入式Docker资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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