Use Symbolic Link with Docker multi-stage builds

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.

Dockerfile example and description

FROM debian:latest as builder
RUN tar czf testlib.tar.gz /usr/local/lib/* \  
            /usr/local/lib/* \
            /usr/local/lib/* #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

Use Symbolic Link with Docker multi-stage builds
Use Puphpeteer with Docker
Use ngrok with Docker
Use GDAL with Python with Docker
[Docker] Use whenever with Docker + Rails
Why use orchestration tools with Docker
Use cuda11.0 with pytorch using Docker
Use ZStandard with .NET Core + Docker (Alpine)
Use Amazon ECR Credential Helper with Docker Desktop
How to use docker compose with NVIDIA Jetson
How to use nginx-ingress-controller with Docker for Mac
Use ProGuard with Gradle
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Why we use Docker
Use XVim2 with Xcode 12.0.1
Use CentOS with LXD
Operate Emby with Docker
Try WildFly with Docker
Run Payara with Docker
Use webmock with Rspec
[Docker] Connection with MySQL
Php settings with Docker
Getting Started with Docker
Use WebJars with Gradle
Use jlink with gradle
Disposable PHP with Docker
Install Composer with Docker
[PHP8] Install and use PECL YAML function (YAML parser) with Docker
Use docker's in-container shell with cygwin [docker exec -it bash]
How to use mysql with M1 mac Docker preview version
You are required to use winpty with docker exec [Windows]