首页 > 解决方案 > 如何在 Docker 容器中使用 Cargo 安装 mdbook?

问题描述

我正在尝试构建一个包含 Rust 和 mdbook 的 Docker 容器。我已经尝试了许多变化

FROM rust:latest
RUN cargo install mdbook

包括指定确切的版本。例如,这些也不起作用

RUN cargo install --git https://github.com/rust-lang-nursery/mdBook.git mdbook

RUN cargo install mdbook --vers "^0.1.0"

当安装到编译lazycell v1.2.0时,事情失败了:

Compiling lazycell v1.2.0
error: `<core::cell::UnsafeCell<T>>::new` is not yet stable as a const fn
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/lazycell-1.2.0/src/lib.rs:233:16
    |
233 |         inner: UnsafeCell::new(None),
    |                ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: in Nightly builds, add `#![feature(const_unsafe_cell_new)]` to the crate attributes to enable

标签: dockerrustrust-cargo

解决方案


您可以构建自己的,而不是使用 Docker 中的 Rust 容器。Rust 的版本仍然是 1.30(与 一样FROM rust:latest),但由于某种原因,此过程正确地获取了所有依赖项。

FROM ubuntu:latest
FROM gcc:latest

RUN apt-get update && \
    apt-get install -y curl

WORKDIR /tmp

RUN curl https://sh.rustup.rs -sSf > rustup.sh
RUN chmod 755 rustup.sh
RUN ./rustup.sh -y
RUN rm /tmp/rustup.sh

RUN ~/.cargo/bin/cargo install mdbook

推荐阅读