如何在 Docker 容器中使用 Cargo 安装 mdbook?

How do I install mdbook using Cargo inside a Docker container?

我正在尝试构建一个包含 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

您可以构建自己的容器,而不是使用 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