我按照教程在Docker映像中运行Rust应用程序。我的Dockerfile中有以下内容:
FROM rust:1.23.0
WORKDIR src/main
COPY . .
RUN cargo install
CMD ["main"]
当我使用docker build -t my-rust-app .
运行此程序时,我会得到以下错误:
error: `std::sync::atomic::AtomicBool::new` is not yet stable as a const fn
--> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/yansi-0.4.0/src/paint.rs:274:30
|
274 | static ENABLED: AtomicBool = AtomicBool::new(true);
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: in Nightly builds, add `#![feature(const_atomic_bool_new)]` to the crate attributes to enable
error: aborting due to previous error
error: Could not compile `yansi`.
我能做些什么来解决这个错误并在Docker容器中运行Rust应用程序?我已经研究了几个小时,并在Dockerfile中尝试了rustup update
和cargo update
的变体,但这些安装都没有解决错误。
在Rust 1.24.0中,调用AtomicBool::new
作为常量是稳定的。使用该版本(或任何更新版本(进行编译可以解决您的问题:
FROM rust:1.24.0