我有我的Dockerfile,看起来像:
FROM confluentinc/cp-kafka-connect:4.0.0
ARG VERSION=0.0.2.15
RUN curl -Ls https://github.com/jcustenborder/kafka-connect-rabbitmq/releases/download/$VERSION/kafka-connect-rabbitmq-$VERSION.tar.gz | tar -xzC /tmp && \
mkdir -p /etc/kafka-connect/jars && \
cp -R /tmp/usr/share/kafka-connect/kafka-connect-rabbitmq/. /etc/kafka-connect/jars && \
ls -l /etc/kafka-connect/jars
RUN ls -l /etc/kafka-connect/jars
现在我面临的问题是,当我第一次这样做时,我可以确认JAR已被复制,正如我所期望的那样.
然而,当我在RUN行中执行第二次ls时,它们不会显示(并且当我运行图像时它们不会出现在我的容器中).
所以我想明白为什么会这样?我错误地假设在每一行之后传递图像 – 因为这似乎并非如此.
仅供参考 – 这是我的控制台的完整输出:
Sending build context to Docker daemon 2.56kB
Step 1/4 : FROM confluentinc/cp-kafka-connect:4.0.0
---> 4db60f092134
Step 2/4 : ARG VERSION=0.0.2.15
---> Using cache
---> dc641b6beb04
Step 3/4 : RUN curl -Ls https://github.com/jcustenborder/kafka-connect-rabbitmq/releases/download/$VERSION/kafka-connect-rabbitmq-$VERSION.tar.gz | tar -xzC /tmp && cp /tmp/usr/share/kafka-connect/kafka-connect-rabbitmq/kafka-connect-rabbitmq-$VERSION.jar /usr/share/java/ && mkdir -p /etc/kafka-connect/jars && cp /tmp/usr/share/kafka-connect/kafka-connect-rabbitmq/*.jar /etc/kafka-connect/jars && ls -l /etc/kafka-connect/jars
---> Running in f48dbf0e487e
total 6804
-rw-r--r-- 1 root root 491199 Apr 2 03:48 amqp-client-4.2.0.jar
-rw-r--r-- 1 root root 74557 Apr 2 03:48 annotations-2.0.1.jar
-rw-r--r-- 1 root root 100811 Apr 2 03:48 connect-utils-0.3.101.jar
-rw-r--r-- 1 root root 7046 Apr 2 03:48 connect-utils-testing-data-0.3.101.jar
-rw-r--r-- 1 root root 1493680 Apr 2 03:48 freemarker-2.3.25-incubating.jar
-rw-r--r-- 1 root root 2256213 Apr 2 03:48 guava-18.0.jar
-rw-r--r-- 1 root root 55784 Apr 2 03:48 jackson-annotations-2.8.0.jar
-rw-r--r-- 1 root root 281079 Apr 2 03:48 jackson-core-2.8.5.jar
-rw-r--r-- 1 root root 1236315 Apr 2 03:48 jackson-databind-2.8.5.jar
-rw-r--r-- 1 root root 749499 Apr 2 03:48 javassist-3.19.0-GA.jar
-rw-r--r-- 1 root root 31212 Apr 2 03:48 kafka-connect-rabbitmq-0.0.2.15.jar
-rw-r--r-- 1 root root 129763 Apr 2 03:48 reflections-0.9.10.jar
-rw-r--r-- 1 root root 41071 Apr 2 03:48 slf4j-api-1.7.21.jar
Removing intermediate container f48dbf0e487e
---> ad2ca0767def
Step 4/4 : RUN ls -l /etc/kafka-connect/jars
---> Running in c0b5fda45249
total 0
Removing intermediate container c0b5fda45249
---> 5fef032d5aba
Successfully built 5fef032d5aba
Successfully tagged myfirstimage:latest
我必须使用某种’finalize’命令吗?
任何帮助,将不胜感激.
谢谢.
最佳答案
我的猜测是/ etc / kafka-connect / jars目录在该映像的Dockerfile中声明为VOLUME.
原文链接:https://www.f2er.com/docker/436268.htmldocker inspect命令的输出确认了我的猜测:
$docker image inspect confluentinc/cp-kafka-connect:4.0.0 --format '{{.Config.Volumes}}'
map[/etc/kafka-connect/secrets:{} /etc/kafka/secrets:{} /var/lib/kafka/data:{} /etc/kafka-connect/jars:{}]
引自The Dockerfile Specification:
If any build steps change the data within the volume after it has been declared,those changes will be discarded.
那么,以下是您的问题的详细信息:
>基本图像声明VOLUME / etc / kafka-connect / jars.
>在Dockerfile的第3步中,您更改了该目录的内容.这就是为什么此步骤中的ls命令正常工作的原因.
>然后丢弃这些更改.
解决方案是将jar文件放在主机上,并在运行容器时将主机目录绑定到容器.如下:
docker run -v /path/contains/jar/files:/etc/kafka-connect/jars