如何通过Dockerfile安装Raku Cro Web框架?安装失败求助
问题描述
尝试用Dockerfile封装基于Raku + Cro Web框架的Web应用时,无法成功安装Cro。使用的Dockerfile如下:
# Use the official Rakudo Star image FROM rakudo-star:latest RUN apt update && \ apt upgrade -y && \ apt install zip -y && \ apt install build-essential -y && \ rm -rf /var/lib/apt/lists/* # Set the working directory inside the container WORKDIR /app # Copy your project files into the container COPY ./bin /app/bin COPY ./config /app/config COPY ./lib /app/lib COPY ./t /app/t COPY ./META6.json /app COPY ./www /app/www RUN zef upgrade zef # install dependencies not in raku.land RUN git clone https://github.com/JuneKelly/perl6-config-clever && \ cd perl6-config-clever && \ zef install . RUN git clone https://github.com/skinkade/crypt-random && \ cd crypt-random && \ zef install . # Install project dependencies RUN zef install --verbose --force --/test Array::Circular RUN zef install --verbose --force --/test Docker::File RUN zef install --verbose --force --/test File::Ignore RUN zef install --verbose --force --/test IO::Socket::Async::SSL RUN zef install --verbose --force --/test Digest::SHA1::Native RUN zef install --debug --/test cro RUN zef install --verbose --force --/test --deps-only . # Expose any necessary ports (optional) # EXPOSE 8080 # Set the default command to run your Raku application CMD ["raku", "/app/bin/app"]
构建时遇到错误:
> [18/20] RUN zef install --verbose --force --/test Cro::HTTP: 2.966 ===> Searching for: Cro::HTTP 37.74 Use of uninitialized value of type IO::Path in string context. 37.74 Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. 82.97 Use of uninitialized value of type IO::Path in string context. 82.97 Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. 82.97 Use of uninitialized value of type IO::Path in string context. 82.97 Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. 82.97 Use of uninitialized value of type IO::Path in string context. 82.97 Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. 82.97 in block at /usr/share/perl6/site/sources/CD3A622C2C09A8A47FE369BE7FE1F5CB7001C1B1 (Zef::Client) line 563 82.97 in block at /usr/share/perl6/site/sources/CD3A622C2C09A8A47FE369BE7FE1F5CB7001C1B1 (Zef::Client) line 563 82.97 in block at /usr/share/perl6/site/sources/CD3A622C2C09A8A47FE369BE7FE1F5CB7001C1B1 (Zef::Client) line 563 82.97 in block at /usr/share/perl6/site/sources/CD3A622C2C09A8A47FE369BE7FE1F5CB7001C1B1 (Zef::Client) line 563 82.97 Use of uninitialized value of type IO::Path in string context. 82.97 Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. <SNIPPED> Dockerfile:38 -------------------- 36 | RUN zef install --verbose --force --/test IO::Socket::Async::SSL 37 | RUN zef install --verbose --force --/test Digest::SHA1::Native 38 | >>> RUN zef install --verbose --force --/test Cro::HTTP 39 | RUN zef install --debug --/test cro 40 | RUN zef install --verbose --force --/test --deps-only . -------------------- ERROR: failed to solve: process "/bin/sh -c zef install --verbose --force --/test Cro::HTTP" did not complete successfully: exit code: 1
解决思路
- 合并Cro相关安装命令:分别安装
Cro::HTTP和cro会导致zef重复处理依赖引发冲突,直接安装cro元包即可自动包含Cro::HTTP等核心组件,将这两步合并为:RUN zef install --debug --/test cro - 切换稳定版Rakudo镜像:
rakudo-star:latest可能是开发版存在兼容性问题,换成具体稳定版本如rakudo-star:2024.02,减少环境不确定性。 - 清理第三方模块仓库:安装完克隆的第三方模块后,删除仓库目录,避免镜像体积冗余和潜在冲突,示例:
同理处理RUN git clone https://github.com/JuneKelly/perl6-config-clever && \ cd perl6-config-clever && \ zef install . && \ cd .. && rm -rf perl6-config-clevercrypt-random仓库。 - 完善META6.json依赖声明:在项目
META6.json的depends字段中正确声明所有依赖(包括cro),这样zef install --deps-only .可自动处理所有模块,无需手动逐个安装,示例:"depends": [ "cro", "Array::Circular", "Docker::File", "File::Ignore", "IO::Socket::Async::SSL", "Digest::SHA1::Native" ] - 更新zef索引:在安装模块前执行
zef update,确保模块索引最新,避免拉取旧版本或找不到模块:RUN zef update && zef upgrade zef
内容的提问来源于stack exchange,提问作者Seamus Brady
相关产品推荐
相关产品推荐

