Rebar3本地依赖安装正常但Docker容器中拉取依赖失败求助
Rebar3在Docker Alpine容器中依赖拉取失败的解决方案
问题现象
本地环境下Rebar3依赖可正常安装,但使用erlang:alpine镜像(OTP版本26.0.1,Rebar3版本3.20.0)构建Docker容器时,所有Git依赖拉取失败,示例错误:
#0 1.936 ===> Failed to fetch and copy dep: {git,"https://github.com/mochi/mochiweb.git", #0 1.936 {ref, #0 1.936 "073349423408e4bae08c90f8d16fee5317e45263"}}
常见原因及解决方法
Alpine镜像缺少Git客户端
Alpine基础镜像默认未安装Git,Rebar3拉取Git依赖必须依赖Git工具支持。在Dockerfile中添加安装步骤:RUN apk add --no-cache gitHTTPS证书验证失败
Alpine默认可能未安装证书包,导致HTTPS请求无法通过证书校验。补充安装证书:RUN apk add --no-cache git ca-certificatesRebar3与OTP版本不兼容
Rebar3 3.20.0和OTP 26.0.1存在兼容性风险,建议升级Rebar3到最新稳定版,替换Dockerfile中的Rebar3安装逻辑:RUN wget -O rebar3 https://github.com/erlang/rebar3/releases/latest/download/rebar3 && \ chmod +x rebar3 && \ mv rebar3 /usr/local/bin/容器网络访问受限
容器内网络可能无法正常访问GitHub,可添加临时测试步骤验证网络连通性:RUN ping github.com -c 3 && \ curl -I https://github.com/mochi/mochiweb.git
完整Dockerfile示例
FROM erlang:26.0.1-alpine # 安装必要工具 RUN apk add --no-cache git ca-certificates # 升级Rebar3到最新稳定版 RUN wget -O rebar3 https://github.com/erlang/rebar3/releases/latest/download/rebar3 && \ chmod +x rebar3 && \ mv rebar3 /usr/local/bin/ WORKDIR /app # 复制项目配置与源码 COPY rebar.config rebar.lock ./ COPY src/ src/ # 拉取依赖并编译 RUN rebar3 get-deps && rebar3 compile
内容的提问来源于stack exchange,提问作者Moeen
相关产品推荐
相关产品推荐

