Dockerize 应用程序或机器?

Dockerize Applications or Machines?

如果我的问题太基础了,我深表歉意,但我才刚刚开始学习docker,有些概念我不太清楚。

我认为docker是一个功能齐全的虚拟机,因此我想到了将具有一组服务的服务器转换为容器。然后我开始阅读 "dockerizing" 应用程序(例如 postgresql), and I learned that a Docker file can only have one default instruction, when executing a container. I read that it is possible to coordinate multiple executing instructions using a supervisor, but I started wondering if that is really the best approach, or if it would be better to lean towards a microservices architecture?

为了更好地阐明我的观点,我想描述一下我的用例。我想创建一个提供 tomcat(通过 servlet 部署一些服务)和 postgreSQL 数据库的环境。理想情况下,我希望服务(和数据库)在同一主机(在不同端口上)运行。

最好为 Tomcat 创建一个容器,为数据库创建一个容器,还是将它们放在同一个容器中运送更好?

如果我创建两个不同的容器,我应该使用哪个框架来编排它们?它 Docker compose 适合这项任务吗?

1)

I think of docker as a fully functional virtual machine, and therefore I thought of transforming a server with a set of services, into a container.

不不不!不是虚拟机

运行 每个容器只有一个进程

在几乎所有情况下,您应该只 运行 单个容器中的单个进程。将应用程序解耦到多个容器中可以更容易地水平扩展和重用容器。如果该服务依赖于另一个服务,请使用容器链接。

阅读编写 Dockerfile 的最佳实践 https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

2)

And if I create two different containers, which framework should I use to orchestrate them? Is it Docker compose appropriated for this task?

您需要从 docker-compose 开始。当您对它更加熟悉时,您就会做出自己有根据的决定。