title: Can Cargo download and build dependencies without also building the application?
body: <p>Is there a way to tell <a href="http://doc.crates.io/guide.html" rel="noreferrer">Cargo</a> to install and build all my dependencies, but not attempt to build my application?</p>
  
  <p>I thought <code>cargo install</code> would do that, but it actually goes all the way to building my app too. I want to get to a state where <code>cargo build</code> would find all dependencies ready to use, but without touching the <code>/src</code> directory.</p>
  
  <hr>
  
  <p><strong>What I'm really trying to accomplish:</strong></p>
  
  <p>I'm trying to build a Docker image for a Rust application, where I'd like to do the following steps:</p>
  
  <p>Build time (<code>docker build .</code>):</p>
  
  <ol>
  <li>import a docker image with rust tooling installed</li>
  <li>add my Cargo.toml and Cargo.lock files</li>
  <li>download and build all dependencies</li>
  <li>add my source directory to the image</li>
  <li>build my source code</li>
  </ol>
  
  <p>Run time (<code>docker run ...</code>):</p>
  
  <ol>
  <li>run the application</li>
  </ol>
  
  <p>I've tried the following <code>Dockerfile</code>, but the indicated step builds my application as well (which of course fails since the source directory isn't there yet):</p>
  
  <pre><code>FROM jimmycuadra/rust
  
  ADD Cargo.toml /source
  ADD Cargo.lock /source
  
  RUN cargo install # &lt;-- failure here
  
  ADD src /source/src
  RUN cargo build
  
  ENTRYPOINT cargo run
  </code></pre>
  
  <p>The reason I want to separate the install dependencies step from actually building my application, is that if I don't change the dependencies, I want Docker to be able use a cached image with all dependencies already installed and built. Thus, I can't <code>ADD /src /source/src</code> until <em>after</em> installing the dependecies, as that would invalidate the cached image when I change my own code.</p>