In order to reduce the size of Docker, multi-stage builds are often used, in which the builder and the image actually used are written in separate stages. When using this multi-stage build, you may want to install the library with the builder and add the library to the actual image with ADD or COPY.
Symbolic links are often included in libraries, but Docker's ADD and COPY commands cannot add symbolic links.
This problem can be solved surprisingly easily by tarning the required Symbolic Link in the builder and extracting the tar file in the next stage.
Let's take a closer look at the actual Dockerfile example.
FROM debian:latest as builder
RUN tar czf testlib.tar.gz /usr/local/lib/test.so.* \
/usr/local/lib/test1.so.* \
/usr/local/lib/test2.so.* #Tar the required Symbolic Link
FROM debian:latest
COPY --from=builder /testlib.tar.gz /testlib.tar.gz #Copy the hardened tar file
RUN cd / && tar xzf testlib.tar.gz #Deploy a solidified Symbolic Link
It seems like a dream that I had a hard time trying to add a Symbolic Link with ADD or COPY until I knew how to do this.
-How to use Docker in Kagawa Lab: Tips on symbolic links
Recommended Posts