rust程序在服务器上能打包成功,但在Dockerfile运行时始终报依赖错误,涉及版本太多即使手动改.lock文件效果也不理想,切换镜像无效果
> [4/4] RUN cargo install --path .:
0.426 Installing backend v0.1.0 (/backend)
0.820 Updating `ustc` index
293.5 error: failed to compile `backend v0.1.0 (/backend)`, intermediate artifacts can be found at `/backend/target`
293.5
293.5 Caused by:
293.5 failed to select a version for the requirement `ahash = "^0.8"`
293.5 candidate versions found which didn't match: 0.4.8, 0.4.1, 0.4.0, ...
293.5 location searched: `ustc` index (which is replacing registry `crates-io`)
293.5 required by package `actix-web v4.5.1`
293.5 ... which satisfies dependency `actix-web = "^4.5.1"` of package `backend v0.1.0 (/backend)`
293.5 perhaps a crate was updated and forgotten to be re-vendored?
------
最后查明问题原因是阿里云docker镜像中的rust最新版本太低,命令行输入:
docker pull rust:latest
docker image inspect rust:latest|grep -I version
得到版本只有1.57.0,更服务器上使用1.79.0相差太远
"DockerVersion": "20.10.7",
"RUST_VERSION=1.57.0"
解决方案:在Dockerfile中升级rust到指定版本: RUN rustup toolchain install 1.79.0 && rustup default 1.79.0
FROM rust:latest
WORKDIR /backend
RUN rustup toolchain install 1.79.0 && rustup default 1.79.0
COPY . .
RUN cargo install --path .
CMD ["backend"]
标签:RUN,rustup,293.5,rust,Docker,1.79,打包,backend
From: https://www.cnblogs.com/lovelifelovekitty/p/18285882