- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 Rust 应用程序,它读取如下 JSON 文件:
fn main() {
let config_dir = std::path::PathBuf::from("config/endpoints.json");
println!(">>>>>>> Canonicalized path {:?}", std::fs::canonicalize(&config_dir));
println!(">>>>>>>>read endpoint file");
println!("Does file exist? {}", std::path::Path::new("config/endpoints.json").exists());
}
应用程序在使用 cargo run
运行时返回正确的文件路径,但是当我将文件添加到类似于 the rust-musl-builder 的 Docker 镜像中时,我得到错误:
Canonicalized pathErr(Os { code: 2, kind: NotFound, message: "No such file or directory" })
Does path exist false
我的 Dockerfile
看起来像这样
FROM ekidd/rust-musl-builder AS builder
# Add our source code.
ADD . ./
RUN sudo chown -R rust:rust /home/rust
RUN cargo build --release
FROM alpine:latest
RUN apk --no-cache add ca-certificates
EXPOSE 3001
COPY --from=builder \
/home/rust/src/config/ \
/usr/local/bin/config/
COPY --from=builder \
/home/rust/src/target/x86_64-unknown-linux-musl/release/app \
/usr/local/bin/
RUN chmod a+x /usr/local/bin/app
ENV RUST_BACKTRACE=1
CMD /usr/local/bin/app
如何读取 Docker 镜像中的文件?
最佳答案
我根据 larsks comment above 找到了这个问题的解决方案:
Also: you seem to be using relative paths in your code. Are you certain those relative paths are going to be correct in your container? You don't have any
WORKDIR
directives, so you working directory is/
.
问题是没有定义 WORKDIR
,因此文件读取发生在路径 /
中。像下面这样更改 Dockerfile(注意 WORKDIR/usr/local/bin
)解决了这个问题:
FROM alpine:latest
RUN apk --no-cache add ca-certificates
EXPOSE 3001
WORKDIR /usr/local/bin
COPY --from=builder \
/home/rust/src/config/ \
/usr/local/bin/config/
COPY --from=builder \
/home/rust/src/target/x86_64-unknown-linux-musl/release/app \
/usr/local/bin/
RUN chmod a+x /usr/local/bin/app
ENV RUST_BACKTRACE=1
CMD /usr/local/bin/app
关于file - 无法使用 std::fs 方法读取 Docker 镜像中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50670951/
我正在尝试将我的Node.js项目迁移到Bun。我的项目在很多地方使用了‘fs’包。我发现了许多Bun迁移示例,它们将‘fs’包导入为‘node:FS’。但是,作为“文件系统”导入可以很好地工作,没有
我正在尝试将我的Node.js项目迁移到Bun。我的项目在很多地方使用了‘fs’包。我发现了许多Bun迁移示例,它们将‘fs’包导入为‘node:FS’。但是,作为“文件系统”导入可以很好地工作,没有
我正在使用 aws lambda。 我有一个 .p8 文件,用于发送 apns 通知。因为我不能使用相对或绝对路径,因为它没有服务器。我必须从 s3 url 读取它。为此我做了这个 let file
我相信以下所有命令都可用于将 hdfs 文件复制到本地文件系统。有什么区别/情境利弊。 (这里是 Hadoop 新手)。 hadoop fs -text /hdfs_dir/* >> /local_d
这是一个新手问题,但我有点困惑为什么需要 open 与 r 、 w 、 a 以及这些标志的所有变体。如果他/她想读取或写入文件而不是使用 open,难道不应该简单地使用 readFile 或 writ
我想在 JavaScript 中使用 import fs from 'fs'。这是一个示例: import fs from 'fs' var output = fs.readFileSync('som
我的公司正在执行 SVN 存储库迁移,我想避免两个存储库(目前都处于事件状态)之间的修订号重叠。 我的要求是将新存储库的修订强制为特定的修订号(例如:100.000)。 通过分析 FSFS 存储库,我
-put和-copyFromLocal被记录为相同,而大多数示例使用详细的变体-copyFromLocal。为什么? -get和-copyToLocal相同 最佳答案 copyFromLocal与pu
我正在调用 Google 云端硬盘的下载 API,然后我想使用 fs.writeFile 或 fs.writeFileSync 在本地写入下载的文件。这就是我正在做的事情: const wri
我正在学习一些教程,但无法理解为什么这一行“self.only_dirs.push(files[i]);”导致有关它“未定义”的错误。这肯定是一个变量范围问题,但我尝试过的都没有成功。我需要如何声明变
我是第一次尝试 phantomJS,我已经成功地从站点中提取了 som 数据,但是当我尝试将一些内容写入文件时,我收到错误:ReferenceError:找不到变量:fs 这是我的脚本 var pag
这是一个 Node 应用程序,运行 Express 服务器。我有一个包含文本文件的文件夹。我需要能够进入文件夹内的每个文件,并提取包含单词“SAVE”的行。 我被困在这一步了。 app.get('/l
我在 fs.chunks 中有 10 GB 的数据,我想删除不在 fs.files 上的所有文档。我已经删除了我不想要的 fs.files 中的每个条目,所以 fs.files 中的每个 id 都是我
我注意到官方 Node 文档对 fs.exists 的描述令人吃惊: "fs.exists() is an anachronism and exists only for historical rea
我用 require("fs").promises只是为了避免使用回调函数。 但是现在,我也想用fs.createReadstream使用 POST 请求附加文件。 我怎样才能做到这一点? 或者在这种
我正在使用 Electron 和 React 编写桌面应用程序。我想将一些信息存储在 JSON 文件中。我试过 web-fs 和 browserify-fs 来完成这个,但都没有按预期工作。我的设置如
其中哪一个更适合在 Node 服务器应用程序的文件管理器类型中处理文件读/写操作? 一个比另一个快吗?速度非常重要,因为该应用程序应该能够同时处理许多用户请求 最佳答案 流的独特之处在于,不是程序像传
我需要递归或不递归地遍历文件夹(给定 bool 参数)。我发现有 fs::recursive_directory_iterator() 和 fs::directory_iterator()。在 Jav
AFAICT,如果我正在编写一个库并使用 Promise.promisifyAll(fs);,这会修改 fs 模块(而不是返回修改后的复制)。因此,如果有人导入我的库,这也会对他们修改 fs 产生副作
我正在使用带有以下导入代码的 fs 模块 导入 fs = require('fs') 代码一直运行,直到在下面的 TypeScript 代码的第二行遇到此异常 const filePath = 'da
我是一名优秀的程序员,十分优秀!