<p>I'm learning Kubernetes. I'm trying to mapping equivalent concept from Kubernetes to Docker. For example: I have a following <code>docker-compose.yml</code></p>

<pre><code>db:
  container_name: db
  image: postgres:latest
  ports:
    - "5432:5432"
  environment:
    POSTGRES_PASSWORD: 1234

app:
  container_name: app
  build: .
  dockerfile: Dockerfile
  ports:
    - "3000:3000"
  volumes:
    - ".:/webapp"
  env_file:
    - ./.env.docker_compose
  links:
    - db
</code></pre>

<p>This <code>docker-compose.yml</code> has two components: db and app. There are 2 ways for understanding. I don't know which one is true and which one is wrong.</p>

<ul>
<li>First understanding: each components are inside in each pod. This means db in one pod, and app in one pod.</li>
<li>Second understanding: both db and app are all in one Pod.</li>
</ul>

<p>Please tell me which one is true. The same question for <code>Deployment</code> and <code>Service</code>. How can I map to docker concept.</p>

<p>Thanks</p>

<p>A pod being a group of one or more container, your docker-compose would by default mimick one pod. (so your second interpretation)</p>

<p>But with <a href="https://docs.docker.com/engine/swarm/" rel="nofollow noreferrer">docker swarm mode</a>, you can make sure those two container are in their own "pod" (as a group of one container) with <a href="https://docs.docker.com/engine/reference/commandline/service_create/#specify-service-constraints-constraint" rel="nofollow noreferrer">constraints</a>.<br>
With dockerfile v3, you have for instance <a href="https://docs.docker.com/compose/compose-file/#placement" rel="nofollow noreferrer"><strong>placement</strong></a> (also seen in <a href="https://docs.docker.com/engine/reference/commandline/service_create/#specify-service-placement-preferences-placement-pref" rel="nofollow noreferrer"><code>docker service create</code></a>)</p>

<pre><code>version: '3'
services:
  db:
    image: postgres
    deploy:
      placement:
        constraints:
          - node.role == manager
          - engine.labels.operatingsystem == ubuntu 14.04
</code></pre>
