首页 > 解决方案 > 无法在 Docker 映像中运行 Rust 应用程序:“作为 const fn 还不稳定”

问题描述

我正在按照教程在 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 updatecargo update但这些安装都没有解决错误。

标签: dockerrust

解决方案


AtomicBool::new作为 const调用在 Rust 1.24.0 中得到了稳定。使用该版本(或任何更新的版本)进行编译可以解决您的问题:

FROM rust:1.24.0

推荐阅读