title: Docker compose yml inheritance
body: <p>There are two tasks: run app container, run almost the same deploy-app container. The differences for them, for example, that deploy container does not have port sharing.</p>
  
  <p>So, I made configs for this tasks...</p>
  
  <p><code>./dockerfiles/base.yml</code>:</p>
  
  <pre><code>app:
      net: docker_internal_net
      environment:
          APPLICATION_SERVER: "docker"
  </code></pre>
  
  <p><code>./dockerfiles/base.run.yml</code>:</p>
  
  <pre><code>app:
      container_name: project-app
      # set the build context to the project root
      build: ..
      volumes:
          - /var/log/project/nginx:/var/log/nginx
          - /var/log/project/php-fpm:/var/log/php5-fpm
          - ..:/var/www/project
  </code></pre>
  
  <p><code>./dockerfiles/dev/run.yml</code>:</p>
  
  <pre><code>app:
      dockerfile: ./dockerfiles/dev/run-app/Dockerfile
      ports:
          - "80:80"
          - "22:22"
      environment:
          DEV_SSH_PUBKEY: "$SSH_PUBLIC_KEY"
          APPLICATION_PLATFORM: "dev"
  </code></pre>
  
  <p><code>./dockerfiles/dev/build.yml</code>:</p>
  
  <pre><code>app:
      container_name: project-app-deploy
      # set the build context to the project root
      build: ../..
      dockerfile: ./dockerfiles/dev/build-app/Dockerfile
      environment:
          APPLICATION_PLATFORM: "dev"
      volumes:
          - ../..:/var/www/project
  </code></pre>
  
  <p>So I can tun the app container like this:</p>
  
  <pre><code>$ docker-compose -f ./dockerfiles/base.yml -f ./dockerfiles/base.run.yml -f ./dockerfiles/dev/run.yml up -d app
  Creating project-app
  
  $ docker ps
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                        NAMES
  dae45f3f2c42        dockerfiles_app     "/sbin/my_init"          2 seconds ago       Up 1 seconds        0.0.0.0:2223-&gt;22/tcp, 0.0.0.0:8081-&gt;80/tcp   project-app
  </code></pre>
  
  <p>Everything okay. But if then I trying to run deploy-app container, I will receive this message:</p>
  
  <pre><code>$ docker-compose -f ./dockerfiles/base.yml -f ./dockerfiles/dev/build.yml up -d app
  Recreating project-app
  WARNING: Service "app" is using volume "/var/www/project" from the previous container. Host mapping ".." has no effect. Remove the existing containers (with `docker-compose rm app`) to use the host volume mapping.
  
  $ docker ps
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
  53059702c09b        dockerfiles_app     "/sbin/my_init"          6 seconds ago       Up 4 seconds        22/tcp, 80/tcp      project-app-deploy
  </code></pre>
  
  <p>This is because both of them are shared one local directory? But why I can run deploy-app container manually without <code>docker-compose</code>?</p>
  
  <pre><code>$ docker run -d --net docker_internal_net -e APPLICATION_SERVER=docker -e APPLICATION_PLATFORM=dev --name project-app-deploy -v ..:/var/www/project mybaseimage
  86439874b8df561f529fde0d1e31824d70dc7e2a2377cd529331a2d7fcb00467
  
  $ docker ps
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                        NAMES
  86439874b8df        mybaseimage         "/sbin/my_init"          4 seconds ago       Up 3 seconds        22/tcp, 80/tcp                               project-app-deploy
  40641f02a09b        dockerfiles_app     "/sbin/my_init"          2 minutes ago       Up 2 minutes        0.0.0.0:2223-&gt;22/tcp, 0.0.0.0:8081-&gt;80/tcp   project-app
  </code></pre>