【发布时间】:2022-05-16 22:16:02
【问题描述】:
我在 Rust + Actix-web 中有 hello world web 项目。我有几个问题。首先是代码的每次更改都会导致重新编译整个项目,包括下载和编译每个 crate。我想像在正常开发中一样工作 - 这意味着缓存已编译的 crate 并且只重新编译我的代码库。第二个问题是它不会暴露我的应用程序。无法通过网络浏览器访问
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
main.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"
【问题讨论】:
-
请同时提供您的 cargo.toml
-
您的 Dockerfile 缺少
CMD行;容器启动时应该运行什么? (构建序列真的完成了吗?) -
如果答案解决了您的问题,请接受它或提供其他信息以进一步调试手头的问题
标签: docker rust dockerfile actix-web