简体   繁体   English

如何在单个 Docker 容器中运行多个 django 服务?

[英]How to run multiple django services in single Docker container?

I have a Django project with a few microservices which heavily rely on django infrastructure itself and have to be started with:我有一个 Django 项目,其中包含一些严重依赖 django 基础设施本身的微服务,并且必须从以下内容开始:

python manage.py sevicename1
python manage.py sevicename2
python manage.py sevicename3
python manage.py sevicename4
python manage.py sevicename...

They all communicate with each other.他们都互相交流。 What is the proper way to run them in one Dockerfile all together?在一个 Dockerfile 中运行它们的正确方法是什么?

It is not possible to cut them out in separate containers.不可能在单独的容器中切出它们。 I fount no better solution and did it in my docker-compose.yml through YAML anchors.我没有找到更好的解决方案,而是通过 YAML 锚点在我的 docker-compose.yml 中完成了。

dg: &dg
  image: python:3.7.6-alpine
   command: ....  --> ( gunicorn --config ./gunicorn.conf.py core.wsgi:application)

dg_run_sevicename1:
  <<: *dg
  restart: on-failure
  ports:
    - 9011:9011
  command: python manage.py sevicename

dg_run_sevicename2:
  <<: *dg
  restart: on-failure
  command: python manage.py sevicename2

dg_run_sevicename3:
...

Unless I agree to bascially multiple the same project source and use separate CMD or ENTRYPOINT at the end of each DOCKERFILE or YML declaration, it is perfectly fine.除非我同意基本多个相同的项目源并在每个 DOCKERFILE 或 YML 声明的末尾使用单独的 CMD 或 ENTRYPOINT,否则完全没问题。 It works.有用。 However the total images size is 3 times bigger than the origin folder itself.然而,总图像大小是原始文件夹本身的 3 倍。 Is it possible to do this in a better way?有没有可能以更好的方式做到这一点?

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

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