Dockerfile ERROR RUN strip target/release/ 在 Windows 上

问题描述 投票:0回答:1

我正在按照一本教程指南进行操作,并且已成功生成 Rest API 响应

当我跑步时

docker build -t my_app . 

出现错误

 ERROR [builder 6/6] RUN strip target/release/my_app                                                                0.4s
------
 > [builder 6/6] RUN strip target/release/my_app:
0.402 strip: 'target/release/cloud-app': No such file
------
Dockerfile:16
--------------------
  14 |     # do a release build
  15 |     RUN cargo build --release
  16 | >>> RUN strip target/release/my_app
  17 |
  18 |     # use a plain alpine image, the alpine version needs to match the builder
--------------------
ERROR: failed to solve: process "/bin/sh -c strip target/release/my_app" did not complete successfully: exit code: 1

这是我的 Dockerfile 的样子

# Start with a rust alpine image
FROM rust:1-alpine3.19 AS builder

# This is important, see https://github.com/rust-lang/docker-rust/issues/85
ENV RUSTFLAGS="-C target-feature=-crt-static"

# if needed, add additional dependencies here
RUN apk add --no-cache musl-dev

# set the workdir and copy the source into it
WORKDIR /app
COPY ./ /app

# do a release build
RUN cargo build --release
RUN strip target/release/my_app

# use a plain alpine image, the alpine version needs to match the builder
FROM alpine:3.19

# if needed, install additional dependencies here
RUN apk add --no-cache libgcc

COPY --from=builder /app/target/release/my_app /usr/local/bin/

ENV ADDRESS=0.0.0.0
ENV PORT=8080

WORKDIR /root

# set the binary as entrypoint
CMD /usr/local/bin/my_app

这是完整的日志

2024/05/07 17:18:36 http2: server: error reading preface from client //./pipe/docker_engine: file has already been closed
[+] Building 47.6s (11/13)                                                                                            docker:default
 => [internal] load build definition from Dockerfile                                                                            0.0s
 => => transferring dockerfile: 838B                                                                                            0.0s
 => [internal] load metadata for docker.io/library/rust:1-alpine3.19                                                            1.2s
 => [internal] load .dockerignore                                                                                               0.0s
 => => transferring context: 2B                                                                                                 0.0s
 => CACHED [builder 1/6] FROM docker.io/library/rust:1-alpine3.19@sha256:..........  0.0s
 => [internal] load build context                                                                                               0.0s
 => => transferring context: 957B                                                                                               0.0s
 => [stage-1 2/4] RUN apk add --no-cache libgcc                                                                                 2.6s
 => CACHED [builder 2/6] RUN apk add --no-cache musl-dev                                                                        0.0s
 => CACHED [builder 3/6] WORKDIR /app                                                                                           0.0s
 => [builder 4/6] COPY ./ /app                                                                                                  0.1s
 => [builder 5/6] RUN cargo build --release                                                                                    45.7s
 => ERROR [builder 6/6] RUN strip target/release/my_app

我是 Rust 新手,之前没有任何 Docker 经验,我只是想学习,使用 alpine 在 Rust 中构建一个小型 docker

rust dockerfile
1个回答
0
投票

如果您查看错误消息:

 > [builder 6/6] RUN strip target/release/my_app:
0.402 strip: 'target/release/cloud-app': No such file

您可以看到它正在为您的应用程序构建一个与您预期不同的名称。该名称在 Cargo.toml 中设置。检查 Cargo.toml 文件并适当设置目录。 (我希望它像

target/release/cloud-app
)。

© www.soinside.com 2019 - 2024. All rights reserved.