在Docker中构建锈项目导致Cargo卡住了下载依赖项

时间:2018-12-28 10:36:04

标签: docker rust dockerfile rust-cargo

我有一个项目尝试使用rust二进制文件构建docker映像,但是当我尝试使用Cargo下载二进制文件时,它卡住了。使用-it运行映像,批量安装src,然后手动运行cargo build可以正常工作。

Dockerfile:

FROM rust:1.31.1 AS builder
# Install protoc
RUN apt-get update && apt-get install -y unzip \
    && PROTOC_ZIP=protoc-3.3.0-linux-x86_64.zip \
    && curl -OL https://github.com/google/protobuf/releases/download/v3.3.0/$PROTOC_ZIP \
    && unzip -o $PROTOC_ZIP -d /usr/local bin/protoc \
    && rm -f $PROTOC_ZIP

COPY . .
RUN cargo test
RUN cargo test --release -- --ignored
RUN cargo build --release

FROM debian
COPY --from=builder /target/release/brqueue /bin/brqueue
RUN chmod +x /bin/brqueue
CMD ["/bin/brqueue"]

我曾经尝试过锈1.31.1和1.30.0。

运行构建最终会得到类似以下的日志:

N:\dev\rust\brqueue>docker build .
Sending build context to Docker daemon  303.1kB
Step 1/10 : FROM rust:1.31.1 AS builder
 ---> d6daf33d7ea6
Step 2/10 : RUN apt-get update && apt-get install -y unzip     && PROTOC_ZIP=protoc-3.3.0-linux-x86_64.zip     && curl -OL https://github.com/google/protobuf/releases/download/v3.3.0/$PROTOC_ZIP     && unzip -o $PROTOC_ZIP -d /usr/local bin/protoc     && rm -f $PRO
TOC_ZIP
 ---> Using cache
 ---> cc1d7cab5aca
Step 3/10 : COPY . .
 ---> 909bab589108
Step 4/10 : RUN cargo test
 ---> Running in 6a9d0bc0a3f1
    Updating crates.io index
 Downloading crates ...
  Downloaded log v0.4.6
  Downloaded crossbeam v0.6.0
  Downloaded futures v0.1.25
  Downloaded serde_derive v1.0.82
  Downloaded bincode v1.0.1
  Downloaded serde v1.0.82
  Downloaded futures-cpupool v0.1.8
  Downloaded uuid v0.7.1
  Downloaded tls-api v0.1.20
  Downloaded bytes v0.4.11
  Downloaded tls-api-native-tls v0.1.20
  Downloaded byteorder v1.2.7
  Downloaded protobuf v2.2.0
  Downloaded protoc-rust v2.2.0
  Downloaded cfg-if v0.1.6
  Downloaded quote v0.6.10
  Downloaded crossbeam-utils v0.6.3
  Downloaded native-tls v0.1.5
  Downloaded crossbeam-epoch v0.7.0
  Downloaded proc-macro2 v0.4.24
  Downloaded crossbeam-channel v0.3.4
  Downloaded num_cpus v1.9.0
  Downloaded iovec v0.1.2
  Downloaded rand v0.5.5
  Downloaded syn v0.15.23
  Downloaded parking_lot v0.7.0
  Downloaded lazy_static v1.2.0
  Downloaded unicode-xid v0.1.0
  Downloaded rand v0.6.1
  Downloaded crossbeam-deque v0.6.3
  Downloaded env_logger v0.6.0
  Downloaded tempdir v0.3.7
  Downloaded arrayvec v0.4.10
  Downloaded protoc v2.2.0
  Downloaded smallvec v0.6.7
  Downloaded rand_core v0.2.2
  Downloaded protobuf-codegen v2.2.0
  Downloaded memoffset v0.2.1
  Downloaded scopeguard v0.3.3
  Downloaded openssl v0.9.24
  Downloaded lazy_static v0.2.11
  Downloaded libc v0.2.45
  Downloaded rustc_version v0.2.3
  Downloaded atty v0.2.11
  Downloaded rand_chacha v0.1.0
  Downloaded regex v1.1.0
  Downloaded parking_lot_core v0.4.0
  Downloaded remove_dir_all v0.5.1
  Downloaded rand_pcg v0.1.1
  Downloaded unreachable v1.0.0
  Downloaded lock_api v0.1.5
  Downloaded rand_core v0.3.0
  Downloaded nodrop v0.1.13
  Downloaded rand_xorshift v0.1.0
  Downloaded humantime v1.2.0
  Downloaded termcolor v1.0.4
  Downloaded void v1.0.2
  Downloaded thread_local v0.3.6
  Downloaded aho-corasick v0.6.9
  Downloaded bitflags v0.9.1
  Downloaded owning_ref v0.4.0
  Downloaded rand v0.4.3
  Downloaded semver v0.9.0
  Downloaded rand_hc v0.1.0
  Downloaded memchr v2.1.2
  Downloaded openssl-sys v0.9.39
  Downloaded foreign-types v0.3.2
  Downloaded quick-error v1.2.2
  Downloaded rand_isaac v0.1.1
  Downloaded utf8-ranges v1.0.2
  Downloaded version_check v0.1.5
  Downloaded regex-syntax v0.6.4
  Downloaded pkg-config v0.3.14
  Downloaded foreign-types-shared v0.1.1
  Downloaded semver-parser v0.7.0
  Downloaded cc v1.0.26
  Downloaded stable_deref_trait v1.1.1
  Downloaded ucd-util v0.1.3

哪个箱子停止运行似乎不稳定,但大致在相同的10个软件包内。

完整的项目代码在这里:https://github.com/zlepper/brqueue(如果有帮助的话)。

1 个答案:

答案 0 :(得分:1)

因此,问题出在COPY . .命令中,因为它只是将所有内容都复制到/中,然后试图对其进行编译(至少这是我的信念)。