rust docker镜像换源

914 阅读1分钟

在 docker build 的时候,如果使用了rust系统镜像或者需要在普通镜像里面使用rust,经常碰到拉取依赖特别慢,还会出现超时错误。

当我们又不想给镜像用代理的时候,可以在dockerfile里面增加下面代码换源:

RUN mkdir ~/.cargo/ && touch ~/.cargo/config \
    && echo '[source.crates-io]' > ~/.cargo/config \
    && echo 'registry = "https://github.com/rust-lang/crates.io-index"'  >> ~/.cargo/config \
    && echo "replace-with = 'tuna'"  >> ~/.cargo/config \
    && echo '[source.tuna]'   >> ~/.cargo/config \
    && echo 'registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"'  >> ~/.cargo/config \
    && echo '[net]'   >> ~/.cargo/config \
    && echo 'git-fetch-with-cli = true'   >> ~/.cargo/config \
    && echo '' >> ~/.cargo/config

使用了字节提供的国内镜像代理RsProxy.cn,也可以根据自己喜好更换别的镜像代理