【问题标题】:Running command after server started - Docker, scrapyd, scrapyd-deploy服务器启动后运行命令 - Docker、scrapyd、scrapyd-deploy
【发布时间】:2018-12-21 20:31:00
【问题描述】:

所以,我有一个Dockerfile,我想在其中保留我的scrapyd 服务器。但是,由于我使用scrapyd-deploy 来部署我的Scrapy 项目,我需要等待scrapyd 服务器运行后再部署鸡蛋。我不确定如何使用Docker 来实现这一点,因为如果我使用scrapyd 作为入口点,它会“窃取”终端并且我无法按顺序运行scrapyd-deploy

目前,我有一些可行的方法,但这对我来说看起来真的非常“老套”,我不喜欢它。正确的做法是什么?

FROM python:3.6
SHELL [ "/bin/bash", "-c" ]

# here comes a lot of configuration, copying files, installing stuff, etc ...

# important part that I think is hacky comes at the end:
# the command below redirect scrapyd streams to /dev/null, send it to the background, deploy the eggs, than run a dummy command to keep the container alive
CMD scrapyd >& /dev/null & cd ali && scrapyd-deploy && tail -f /dev/null

有什么想法或建议吗?

【问题讨论】:

    标签: docker scrapy dockerfile scrapyd


    【解决方案1】:

    是的,我知道使用 Linux 管理进程应该不会那么复杂。 #loveLinux #linuxRocks

    所以,我找到了一种将scrapyd 服务器进程置于后台的方法,使用scrapyd-deploy 进行部署,然后再次将服务器返回前台以避免Docker 杀死我的容器。这就是解决所有问题的CMD 行(使用 cmets):

    # Set bash monitor mode on; run server on the background, deploy eggs, get server to the foreground again.
    CMD set -m; scrapyd & cd ali && scrapyd-deploy && fg scrapyd
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-09
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多