Rust项目使用Dockerfile构建镜像 访问crates.io下载速度慢解决

发布时间 2023-09-07 18:21:55作者: Xianhao

在 $CARGO_HOME/config文件添加国内的镜像源

下面的镜像源来自:https://rsproxy.cn/

FROM rust:1.72 as builder 

WORKDIR /usr/src

COPY . .

RUN  echo "[source.crates-io]\n\ 
replace-with = 'rsproxy-sparse'\n\
[source.rsproxy]\n\
registry = \"https://rsproxy.cn/crates.io-index\"\n\
[source.rsproxy-sparse]\n\ 
registry = \"sparse+https://rsproxy.cn/index/\"\n\ 
[registries.rsproxy]\n\ 
index = \"https://rsproxy.cn/crates.io-index\"\n\ 
[net]\n\
git-fetch-with-cli = true\n" >> $CARGO_HOME/config