从 ubuntu 绝对路径复制 Docker

在我的 dockerfile 中有以下行

COPY /root/url.net/volumes/persistent/url/root /usr/share/nginx/html

当我尝试建立与码头构图的形象,我得到

服务“前端”构建失败: lstat /root/ url.net/volumes/persistent/url/root : 没有这样的文件或 目录

我可以从任何地方的 CD 到 /root/url.net/volumes/persistent/url/root在我的机器上没有问题。

如何在 dockerfile 中指定文件夹的绝对路径?

65279 次浏览

You can't. You have to copy/hardlink the files/folders inside the directory where you build the docker image.

The absolute path of your resources refers to an absolute path within the build context, not an absolute path on the host. So all the resources must be copied into the directory where you run the docker build and then provide the path of those resources within your Dockerfiles before building the image. (This refers to the location where you run your Dockerfile)

There is a closed issue for this as well.