我在Rust+Actix-web中有一个“Hello World”网站项目,遇到了几个问题。首先是代码的每一次更改都会导致整个项目重新编译,包括下载和编译每个crate,希望能像普通开发一样工作——即缓存已编译的crates,仅重新编译我的代码库。第二个问题是我的应用程序无法通过Web浏览器访问。
Dockerfile:
FROM rust
WORKDIR /var/www/app
COPY . .
EXPOSE 8080
RUN cargo run
docker-compose.yml:
version: "3"
services:
app:
container_name: hello-world
build: .
ports:
- '8080:8080'
volumes:
- .:/var/www/app
- registry:/root/.cargo/registry
volumes:
registry:
driver: local
主函数.rs:
extern crate actix_web;
use actix_web::{web, App, HttpServer, Responder};
fn index() -> impl Responder {
"Hello world"
}
fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(web::resource("/").to(index)))
.bind("0.0.0.0:8080")?
.run()
}
Cargo.toml:
[package]
name = "hello-world"
version = "0.1.0"
authors = []
edition = "2018"
[dependencies]
actix-web = "1.0"
CMD
行;容器启动时应该运行什么?(构建序列是否实际完成?) - David Maze