docker - 无法在 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 update
,cargo update
但这些安装都没有解决错误。
解决方案
AtomicBool::new
作为 const调用在 Rust 1.24.0 中得到了稳定。使用该版本(或任何更新的版本)进行编译可以解决您的问题:
FROM rust:1.24.0
推荐阅读
- gcc - 无法在生成文件中链接静态库
- iis - 为什么 IIS 关心查询字符串中是否拼错了“convert”?
- php - 注意未定义的索引:
- thingsboard - 我可以在不使用 ThingsBoard 上的 Web UI 而是从命令行添加设备吗?
- c - Google Kickstart 2020 Round A 分配问题
- c# - Flatpickr 加载为上午时间而不是下午时间
- google-apps-script - 我的 OnFormSubmit 触发器需要在加载项的 OnFormSubmit 触发器触发之前完成
- node.js - 如何使用 express 模拟导入的依赖项?
- c++ - GCC 无法编译 OpenMP 卸载到 GPU
- maven - 如何正确配置 Maven 安装和 Maven 存储库位置?