如何在Docker容器中运行Lektor?

问题描述:

我试图在码头集装箱内运行lektor,并遇到问题。如何在Docker容器中运行Lektor?

如果我在我的Dockerfile中添加了我的源代码文件夹,那么一切正常,但是当然,容器不是动态的,并且不会响应代码中的更改。

如果我使用卷,容器变为动态,并且lektor在我进行更改时成功重建并为我的网站提供服务。

然而,当我来到发布现场,出现在容器中的日志中的错误,并进入一个永无休止的循环:

Started build Debugging middleware caught exception in streamed response at a point where response headers were already sent. Traceback (most recent call last): File "/usr/local/lib/lektor/lib/python2.7/site-packages/lektor/admin/utils.py", line 18, in generate for event in chain(f(*args, **kwargs), (None,)): File "/usr/local/lib/lektor/lib/python2.7/site-packages/lektor/admin/modules/api.py", line 309, in generator for event in event_iter: File "/usr/local/lib/lektor/lib/python2.7/site-packages/lektor/publisher.py", line 639, in publish self.link_artifacts(path) File "/usr/local/lib/lektor/lib/python2.7/site-packages/lektor/publisher.py", line 602, in link_artifacts link(full_path, dst) OSError: [Errno 18] Invalid cross-device link

最小Dockerfile:

FROM python:2.7.11 

RUN curl -sf https://www.getlektor.com/install.sh | \ 
    sed '/stdin/d;s/input = .*/return/' | \ 
    sh 

我实际上是在使用docker-compose。

最小的码头工人,compose.yml: version: '2' services: web: build: . ports: - "5000:5000" volumes: - .:/project working_dir: /project/source command: ['lektor', 'server', '--host', '0.0.0.0.']

(我的项目文件夹的结构使得LEKTOR项目文件和所有预期LEKTOR文件夹中的“源”子文件夹)。

+0

“无效的跨设备链接”的快速谷歌显示与符号链接的东西。 Lektor在发布时做了什么(我听说过但没有使用它)?它有可能试图在容器和容器中的东西之间创建符号链接?那里可能有问题?也许权限。似乎开始的地方。 – johnharris85

+0

是的,lektor试图使用链接,它不喜欢卷的安装方式。 – Owen

+0

看起来,构建过程使用硬链接,并且输出文件夹不在源代码路径中。由于源代码是已安装的卷,并且构建文件夹位于容器中的其他位置,因此两个文件系统不同,硬链接失败。 – Owen

lektor构建过程对构建文件使用硬链接和临时文件夹。如果源代码位于已装入的卷上(它位于docker卷中),那么这两个文件系统是不同的,并且链接失败,如上所述。

通过命令行进行部署和构建并指定输出路径可解决此问题(在此处进行了描述:https://www.getlektor.com/docs/deployment/),但在Docker容器中这不是一个很好的解决方案,其目的是让生活尽可能简单。

在某些情况下,在lektor内进行链接的方法实际上会退回到复制。我创建了一个问题(https://github.com/lektor/lektor/issues/315),暗示还会发生倒退,即项目和输出文件夹位于不同的卷上。我怀疑这会正确地解决问题。