I have this docker file:
FROM alpine/git AS git
RUN apk fix && apk --no-cache --update add zip
VOLUME /root
WORKDIR /root
FROM minio/mc AS minio
COPY --from=git /usr/bin/git /usr/bin/git
COPY --from=git /usr/bin/zip /usr/bin/zip
ENTRYPOINT ["sh"]
Basically I need the following tools:
- git
- minio client
- zip
Which, per the docs I read, the above should work – it builds without and error
But when I try to execute anything I get:
Sending build context to Docker daemon 8.192kB
Step 1/8 : FROM alpine/git AS git
---> 22d84a66cda4
Step 2/8 : RUN apk fix && apk --no-cache --update add zip
---> Using cache
---> 5ce4d94085d9
Step 3/8 : VOLUME /root
---> Using cache
---> 89329e40cbba
Step 4/8 : WORKDIR /root
---> Using cache
---> 37f2c9216bb1
Step 5/8 : FROM minio/mc AS minio
---> 396036e5ac42
Step 6/8 : COPY --from=git /usr/bin/git /usr/bin/git
---> 543676360b6d
Step 7/8 : COPY --from=git /usr/bin/zip /usr/bin/zip
---> 936165b36d2e
Step 8/8 : ENTRYPOINT ["sh"]
---> Running in 4ee0c4b491f9
Removing intermediate container 4ee0c4b491f9
---> 1279af2dd755
Successfully built 1279af2dd755
Successfully tagged fabric:latest
[centos@ip-10-6-5-12 ~]$ sudo docker run -it fabric
sh-4.4# which zip
sh: which: command not found
sh-4.4# zip
sh: /usr/bin/zip: No such file or directory
sh-4.4# which git
sh: which: command not found
sh-4.4# git
sh: /usr/bin/git: No such file or directory
sh-4.4# git
sh: /usr/bin/git: No such file or directory
sh-4.4# apt
sh: apt: command not found
sh-4.4# ls -al /usr/bin/git
-rwxr-xr-x. 1 root root 2911912 Oct 19 04:51 /usr/bin/git
So, the file is there. Root (me) owns it and yet it says No such file or directory
? I am perplexed
Anyone know what’s up?
2
Answers
Conclusion
Don’t use copy to add git or zip, because they have dependencies, just copying git or zip is not enough.
Dockerfile
Install Log
From the installation log, you can see that git or zip has other dependent packages that need to be installed.
Run it
Dokcer image size
You’ve copied binaries that are linked against dynamic libraries that don’t exist in your target image:
When copying binaries into an image, they need to either be statically linked, or you need to ensure all of the libraries already exist in the target image. Linux package managers do this for you, which in the target image you’ve picked is
microdnf
: