title: Remote `docker-compose build`: workaround slow connections
body: <p>I'm using docker-compose to deploy into a remote host. This is what my config looks like:</p>
  
  <pre><code># stacks/web.yml
  version: '2'
  
  services:
    postgres:
      image: postgres:9.6
      restart: always
      volumes:
        - db:/var/lib/postgresql/data
  
    redis:
      image: redis:3.2.3
      restart: always
  
    web_server:
      depends_on: [postgres]
      build: ../sources/myapp
      links: [postgres]
      restart: always
      volumes:
        - nginx_socks:/tmp/socks
        - static_assets:/source/public
  
    sidekiq:
      depends_on: [postgres, redis]
      build: ../sources/myapp
      links: [postgres, redis]
      restart: always
      volumes:
        - static_assets:/source/public
  
    nginx:
      depends_on: [web_server]
      build: ../sources/nginx
      ports:
        - "80:80"
      volumes:
        - nginx_socks:/tmp/socks
        - static_assets:/public
      restart: always
  
  volumes:
    db:
    nginx_socks:
    static_assets:
  
  # stacks/web.production.yml
  version: '2'
  
  services:
    web_server:
      command: bundle exec puma -e production -b unix:///tmp/socks/puma.production.sock
      env_file: ../env/production.env
  
    sidekiq:
      command: bundle exec sidekiq -e production -c 2 -q default -q carrierwave
      env_file: ../env/production.env
  
    nginx:
      build:
        args:
          ENV_NAME: production
          DOMAIN: production.yavende.com
  </code></pre>
  
  <p>I deploy using:</p>
  
  <pre><code>eval $(docker-machine env myapp-production)`
  docker-compose -f stacks/web.yml -f stacks/web.production.yml -p myapp_production build -no-deps web_server sidekiq
  docker-compose -f stacks/web.yml -f stacks/web.production.yml -p myapp_production up -d
  </code></pre>
  
  <p>Although this works perfectly locally, and I did couple successful deploys in the past with this method, now it hangs when building the "web_server" service and finally show some timeout error, like I describe in <a href="https://github.com/docker/compose/issues/3975" rel="nofollow">this issue</a>.</p>
  
  <p>I think that the problem originates from the combination of my slow connection (Argentina -> DigitalOcean servers on USA) and me trying to build images and push them instead of using hub hosted images.</p>
  
  <p>I've been able to do deploy by cloning my compose config into the server and running <code>docker-compose</code> directly there.</p>
  
  <p>The question is: <strong>is there a better way to automate this process? Is a good practice to use docker-compose to build images on the fly?</strong></p>
  
  <p>I've been thinking about automating this process of cloning sources into the server and <code>docker-compose</code>ing stuff, but there may be better tooling to solve this matter.</p>