title: Docker compose with Dockerfile creates multiple images instead of one
body: <p>I have a docker-compose.yml and Dockerfile in the same folder. When running docker compose build this should result in one image and one container, but somehow I'm left with two images and two containers. The same docker-compose.yml and Dockerfile on my desktop however results in one image. What is happening here?</p>
  <p>docker-compose.yml</p>
  <pre><code>    version: '3.3'
      services:
          nginx-proxy: 
              build: .
              restart: always
              ports:
                  - '80:80'
                  - '443:443'
              volumes:
                  - /etc/nginx/certs/domain.nl.crt:/etc/letsencrypt/live/domain.nl/cert.pem:ro
                  - /etc/nginx/certs/domain.nl.key:/etc/letsencrypt/live/domain.nl/privkey.pem:ro
                  - /var/run/docker.sock:/tmp/docker.sock:ro
  </code></pre>
  <p>Dockerfile:</p>
  <pre><code>FROM nginxproxy/nginx-proxy
  EXPOSE 80
  EXPOSE 443
  </code></pre>
  <p>The output of <code>docker compose build</code> looks completely different on the server and on my desktop too.</p>
  <p>Running <code>docker compose build</code> Linux server:</p>
  <pre><code>Sending build context to Docker daemon     404B
  Step 1/3 : FROM nginxproxy/nginx-proxy
  latest: Pulling from nginxproxy/nginx-proxy
  f7a1c6dad281: Pull complete
  4d3e1d15534c: Pull complete
  9ebb164bd1d8: Pull complete
  59baa8b00c3c: Pull complete
  a41ae70ab6b4: Pull complete
  e3908122b958: Pull complete
  3016ffcb703f: Pull complete
  d0b58d19b229: Pull complete
  e75e1b46ae51: Pull complete
  a1b8f07fa83d: Pull complete
  b1ff9eda0cc4: Pull complete
  d334f8d44841: Pull complete
  4f4fb700ef54: Pull complete
  Digest: sha256:5e0be3b1bb035301c5bb4edbe0dee5bc0f133d26866e3165f1912acb126e15d4
  Status: Downloaded newer image for nginxproxy/nginx-proxy:latest
   ---&gt; 65d9e0769695
  Step 2/3 : EXPOSE 80
   ---&gt; Running in 4bdc00f75332
   ---&gt; 0ca795ce85fb
  Step 3/3 : EXPOSE 443
   ---&gt; Running in 3530eba2d3cf
   ---&gt; 9440ccab1790
  Successfully built 9440ccab1790
  Successfully tagged nginx-proxy_nginx-proxy:latest
  </code></pre>
  <p>Result:</p>
  <pre><code>docker image ls -a
  REPOSITORY                TAG       IMAGE ID       CREATED          SIZE
  &lt;none&gt;                    &lt;none&gt;    0ca795ce85fb   46 minutes ago   156MB
  nginx-proxy_nginx-proxy   latest    9440ccab1790   46 minutes ago   156MB
  nginxproxy/nginx-proxy    latest    65d9e0769695   4 days ago       156MB
  
  docker container ls -a
  CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS    PORTS     NAMES
  3530eba2d3cf   0ca795ce85fb   &quot;/app/docker-entrypo…&quot;   25 seconds ago   Created             affectionate_vaughan
  4bdc00f75332   65d9e0769695   &quot;/app/docker-entrypo…&quot;   25 seconds ago   Created             fervent_varahamihira
  
  </code></pre>
  <p>Running <code>docker compose build</code> Desktop:</p>
  <pre><code>[+] Building 2.4s (5/5) FINISHED
   =&gt; [internal] load build definition from Dockerfile                                                                                         0.1s
   =&gt; =&gt; transferring dockerfile: 31B                                                                                                          0.0s
   =&gt; [internal] load .dockerignore                                                                                                            0.1s
   =&gt; =&gt; transferring context: 2B                                                                                                              0.0s
   =&gt; [internal] load metadata for docker.io/nginxproxy/nginx-proxy:latest                                                                     2.1s
   =&gt; CACHED [1/1] FROM docker.io/nginxproxy/nginx-proxy@sha256:5e0be3b1bb035301c5bb4edbe0dee5bc0f133d26866e3165f1912acb126e15d4               0.0s
   =&gt; exporting to image                                                                                                                       0.1s
   =&gt; =&gt; exporting layers                                                                                                                      0.0s
   =&gt; =&gt; writing image sha256:f66ed6ec69a319ce3a15b1f1948720bdd8174d13299513cc162a812616874793                                                 0.0s
   =&gt; =&gt; naming to docker.io/library/nginx-proxy_nginx-proxy
  </code></pre>
  <p>Result:</p>
  <pre><code>docker image ls -a
  REPOSITORY                TAG       IMAGE ID       CREATED       SIZE
  nginx-proxy_nginx-proxy   latest    f66ed6ec69a3   4 days ago    156MB
  
  docker container ls -a
  CONTAINER ID   IMAGE                    COMMAND         CREATED       STATUS       PORTS                                          NAMES
  </code></pre>