Skip to main content
 首页 » 编程设计

python之3 种不同的应用程序和 docker 容器

2024年08月22日37shihaiming

我想先在本地 Docker 中设置 Kabana 和 Elastic Search,以显示来自不在本地 docker 容器中的 Python 网络应用程序的日志。虽然,在服务器上,Python 应用程序位于 docker 容器中。

Kabana 和 Elastic Search 根本没有在服务器上和本地设置。

  • 是否可以将 Kabana 和 Elastic Searcn 放入不同的 docker 容器中,还是应该将它们放入一个容器中?更新:推荐哪个选项?

  • 如果只有一个,在同时存在 Kabana 和 Elastic Search 的地方没有可用的 docker 镜像,我该怎么办?

  • 他们是否能够从我不在 docker 容器中的本地 Python 网络应用程序中检索日志,或者我是否必须将 python 应用程序也放入容器中?如果是后者,是单独的容器还是应该和 Kibana 和 Elastic Search 放在同一个容器里?

请您参考如下方法:

我会尽量回答你的问题:

  1. 是的,这是可能的,因为容器可以与另一个容器通信。

Links allow containers to discover each other and securely transfer information about one container to another container. When you set up a link, you create a conduit between a source container and a recipient container. The recipient can then access select data about the source. To create a link, you use the --link flag.

  1. 您可以创建自定义图像。

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession. More -> https://docs.docker.com/engine/reference/builder/

  1. 你最好放在一个容器里,可以毫无问题地分开。

为了更好地管理您的所有设置,我建议您查看 Docker Compose .

下面是两个容器如何链接的示例:

elasticsearch: 
  image: elasticsearch 
  ports: 
    - 9200:9200 
 
kibana: 
  image: kibana 
  ports: 
    - 5601:5601 
  environment: 
    - ELASTICSEARCH_URL=http://elasticsearch:9200 
  links: 
    - elasticsearch