title: Docker-compose: replace "build"-based service with pre-built image in production?
body: <p>Let's say we have the following <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3'
  services:
    db:
      image: "postgres"
      ports:
       - "5432:5432"
      environment:
       - POSTGRES_PASSWORD=mysecretpassword
    web:
      build: web
      depends_on: [ db ]
      ports:
       - "80:80"
  </code></pre>
  
  <p>The first service, <code>db</code>, just runs a container with the official postgres image from Docker Hub. </p>
  
  <p>The second service, <code>web</code>, first builds a new image based on the <code>Dockerfile</code> in a folder also called <code>web</code>, then runs a container with that image.</p>
  
  <p>While developing, we now can (repeatedly) make changes to whatever is in the <code>web</code> folder, then run <code>docker-compose up --build</code> to run our app locally. </p>
  
  <p>Let's say we now want to deploy to production. My understanding is that <code>docker-compose.yml</code> can now be used to "define a stack in Docker's swarm mode" (see <a href="https://stackoverflow.com/a/37966689">this</a> answer, for instance). However, for the <code>build</code> step of the <code>web</code> service, Docker's <a href="https://docs.docker.com/compose/compose-file/#build" rel="noreferrer">compose file documentation</a> states that </p>
  
  <blockquote>
    <p>This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file. The docker stack command accepts only pre-built images.</p>
  </blockquote>
  
  <p>It probably wouldn't be a great idea to build the image on the production machine anyways, as this would leave build artifacts (source code) behind; this should happen on a build server.</p>
  
  <p>My question is, is there a recommended way to modify <code>docker-compose.yml</code> en route to production to swap out <code>build: web</code> with <code>image: &lt;id&gt;</code> somehow? </p>
  
  <p>Nothing on <a href="https://docs.docker.com/compose/production/" rel="noreferrer">Use Compose in production</a> on that. Is there something wrong with my approach in general?</p>