title: Cache Rust dependencies with Docker build
body: <p>I have hello world web project in Rust + Actix-web. I have several problems. First is every change in code causes recompiling whole project including downloading and compiling every crate. I'd like to work like in normal development - it means cache compiled crates and only recompile my codebase. Second problem is it doesn't expose my my app. It's unreachable via web browser</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM rust
  
  WORKDIR /var/www/app
  
  COPY . .
  
  EXPOSE 8080
  
  RUN cargo run
  </code></pre>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: "3"
  services:
    app:
      container_name: hello-world
      build: .
      ports:
        - '8080:8080'
      volumes:
        - .:/var/www/app
        - registry:/root/.cargo/registry
  
  volumes:
    registry:
      driver: local
  </code></pre>
  
  <p>main.rs:</p>
  
  <pre><code>extern crate actix_web;
  
  use actix_web::{web, App, HttpServer, Responder};
  
  fn index() -&gt; impl Responder {
      "Hello world"
  }
  
  fn main() -&gt; std::io::Result&lt;()&gt; {
      HttpServer::new(|| App::new().service(web::resource("/").to(index)))
          .bind("0.0.0.0:8080")?
          .run()
  }
  </code></pre>
  
  <p>Cargo.toml:</p>
  
  <pre><code>[package]
  name = "hello-world"
  version = "0.1.0"
  authors = []
  edition = "2018"
  
  [dependencies]
  actix-web = "1.0"
  </code></pre>