docker - 如何在多阶段docker build中访问克隆的git repo?

标签 docker

我有一个dockerized logstash,我想添加一个附加插件logstash-input-pulsar
该插件需要通过git clone下载,其依赖项需要使用jruby进行安装:

bundle install
rake install_jars
我想我可以先使用git镜像来git clone插件,然后使用jruby镜像cd到plugin文件夹并安装gems。但是,当我尝试将CD插入插件文件夹时,出现此错误:
/bin/sh: 1: cd: can't cd to logstash-input-pulsar
当我尝试构建Dockerfile时,完整的消息是:
[logstash (master)]$ docker build -t logstash .
Sending build context to Docker daemon  70.03MB
Step 1/10 : ARG ELK_VERSION
Step 2/10 : FROM alpine/git
 ---> f54f496311fb
Step 3/10 : RUN git clone https://github.com/se7enkings/logstash-input-pulsar
 ---> Using cache
 ---> 93b473ae8753
Step 4/10 : FROM jruby:9
 ---> 4e5c810afeb7
Step 5/10 : RUN cd logstash-input-pulsar
 ---> Running in c1b9158d91d0
/bin/sh: 1: cd: can't cd to logstash-input-pulsar
The command '/bin/sh -c cd logstash-input-pulsar' returned a non-zero code: 2
Dockerfile是:
ARG ELK_VERSION

FROM alpine/git as intermediate
RUN git clone https://github.com/se7enkings/logstash-input-pulsar

FROM jruby:9
COPY --from=intermediate /logstash-input-pulsar /logstash-input-pulsar
RUN cd /logstash-input-pulsar
RUN bundle install
RUN rake install_jars

# https://www.docker.elastic.co/
FROM docker.elastic.co/logstash/logstash:${ELK_VERSION}
RUN echo 'gem "logstash-input-pulsar", :path => "logstash-input-pulsar"
RUN bin/logstash-plugin install --no-verify
我认为一旦git镜像销毁,logstash-input-pulsar文件夹就不会保留。但是我不确定如何将这些命令链接在一起。

最佳答案

似乎该问题是由于基本镜像上的克隆没有正确的路径而引起的。
您可以在Dockerfile下面尝试,它应该可以工作。

FROM alpine/git as intermediate
WORKDIR /app
RUN git clone https://github.com/se7enkings/logstash-input-pulsar

FROM jruby:9
COPY --from=intermediate /app/ /app
WORKDIR /app/logstash-input-pulsar
RUN bundle install
RUN rake install_jars

关于docker - 如何在多阶段docker build中访问克隆的git repo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62660588/

相关文章:

perl - 从环境变量配置 Dancer?

docker - 发生错误 :Nosuch container? 时如何将文件复制到 docker 容器

docker - Kubernetes上部署的Spring Boot应用如何判断CrashLoopBackOff错误的原因

docker - 如何让 SSL 与 .net core 和 Google Compute Engine 一起工作?

docker - 创建前检查错误:激活Hyper-V时, "This computer is running Hyper-V. VirtualBox won' t引导64位VM

linux - Alpine Linux 3.7 上的 Docker 容器 : Strange pid 1 not visible within the container's pid namespace

apache-spark - neo4j-mazerunner,如何在 docker-compose.yml 中增加内存大小

php - PHP状态页有效,但Nginx记录错误

docker - 托管 Linux 预览代理上的缓存 Docker 镜像

node.js - Chrome 中的 Webpack 不完整 block 编码