与luigi docker服务器共享卷

时间:2019-10-05 12:09:12

标签: python docker luigi

我正在尝试使用docker和luigi https://hub.docker.com/r/spotify/luigi

我用spotify / luigi创建了一个docker容器。我对此很陌生,似乎无法通过控制台访问该图像。

我创建了一个共享卷并将其映射到容器的/ luigi / share /

import luigi
import time

class HelloWorld(luigi.Task):
    def requires(self):
        return None
    def output(self):
        return luigi.LocalTarget('/luigi/share/helloworld3.txt')
    def run(self):
        time.sleep(1)
        with self.output().open('w') as outfile:
            outfile.write('Hello World!\n')
        time.sleep(1)

class NameSubstituter(luigi.Task):
    name = luigi.Parameter()

    def requires(self):
        return HelloWorld()
    def output(self):
        return luigi.LocalTarget(self.input().path + '.name_' + self.name)
    def run(self):
        time.sleep(1)
        with self.input().open() as infile, self.output().open('w') as outfile:
            text = infile.read()
            text = text.replace('World', self.name)
            outfile.write(text)
        time.sleep(1)

if __name__ == '__main__':
    luigi.run()

这是我使用python test.py --scheduler-host 192.168.178.48 NameSubstituter运行的示例代码

当我现在查看具有共享卷的另一个容器时,没有创建文本文件。

我在这里迷路了...

提前谢谢

1 个答案:

答案 0 :(得分:0)

直接从Python运行test.py时,实际上并没有通过docker运行任何东西。您需要按照实际设置容器内部test.py的说明进行操作,然后从docker运行它。该链接可能包含更多信息:How to run my python script on docker?