How to reference embedded Docker resource files using file path URL

流过昼夜 提交于 2019-12-11 21:56:14

问题


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

COPY resources /resources

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

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

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

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

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


回答1:


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.




回答2:


As per the official doc on https://www.pdfreactor.com/product/doc_html/index.html#resourceLoading

It is also possible to specify file URLs:

Java: config.setBaseURL("file:///directory/")

PHP: $config["baseURL"] = "file:///directory/";

.NET: config.BaseURL = "file:///directory/";

CLI: --baseURL "file:///directory/"



来源:https://stackoverflow.com/questions/51522649/how-to-reference-embedded-docker-resource-files-using-file-path-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!