简体   繁体   English

Docker中的多个Python脚本

[英]Multiple Python Scripts in Docker

This is quite a basic question but I haven't been able to get an answer from researching on Google, although I think its more due to my lack of understanding, than the answer not being out there. 这是一个非常基本的问题,但是我无法从Google的研究中获得答案,尽管我认为这更多是由于我缺乏理解,而不是因为没有答案。

I am getting to grips with Docker and have a python Flask Admin script and a postgres db both in two separate containers but under on docker-compose file. 我开始接触Docker,并且在两个单独的容器中但在docker-compose文件下都有一个python Flask Admin脚本和一个postgres db。 I would like another python script to run at the same time which will be scraping a website. 我想同时运行另一个python脚本,这将抓取一个网站。 I have the file all set up but how do I include it in the same Docker-Compose or DockerFile? 我已经全部设置了文件,但是如何将其包含在同一Docker-Compose或DockerFile中?

version: '2'
services:
  db:
    image: postgres
    environment:
      - PG_PASSWORD=XXXXX
  dev:
    build: .
    volumes:
      - ./app:/code/app
      - ./run.sh:/code/run.sh
    ports:
      - "5000:5000"
    depends_on:
       - db

Exactly what to write depends on your directory configuration, but you basically want 确切地写什么取决于您的目录配置,但是您基本上想要

version: '2'
services:
  db:
    image: postgres
    environment:
      - PG_PASSWORD=XXXXX
  dev:
    build: <path-to-dev>
    volumes:
      - ./app:/code/app
      - ./run.sh:/code/run.sh
    ports:
      - "5000:5000"
    depends_on:
      - db
  scraper:
    build: <path-to-scraper>
    depends_on:
      - db

The two paths might be the same. 两条路径可能相同。 You might push an image and then reference that instead of building it on the fly. 您可以推送图像,然后引用它,而不是动态构建它。 You might do the same business of just mounting the code directory instead of building it into the image (but don't do that for actual deployment). 您可能会做同样的事情,只是挂载代码目录而不是将其构建到映像中(但在实际部署中不要这样做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM