如何在保留符号链接的同时在多阶段Docker构建的各个阶段之间复制库文件? [英] How to COPY library files between stages of a multi-stage Docker build while preserving symlinks?

查看:134
本文介绍了如何在保留符号链接的同时在多阶段Docker构建的各个阶段之间复制库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dockerfile,该文件分为两个阶段的多阶段docker构建。第一阶段生成一个基本的gcc构建环境,在该环境中编译了许多C和C ++库。第二阶段使用 COPY --from = 命令从第一阶段 / usr / local / lib / libproto * 到当前图像。

I have a Dockerfile which is split into a two-stage multi-stage docker build. The first stage generates a basic gcc build environment in which a number of C and C++ library are compiled. The second stage uses the COPY --from= command to copy the library files from the first stages /usr/local/lib/libproto* to the current image's.

我看到的问题是,第一张图像包含从通用库文件名到特定版本文件名的符号链接。 AFAIK这是Debian和许多其他Linux系统中的常见做法。 Docker的 COPY 命令似乎不理解符号链接,因此制作了两个完整的库文件副本。这样会导致更大的Docker映像大小,并从后面的 apt-get 命令到 ldconfig:/ usr / local / lib / libprotobuf发出警告。 so.17不是符号链接

The problem I am seeing is that the first image contains symlinks from a generic library file name to a specific versioned file name. AFAIK this is common practice within Debian and many other Linux systems. Docker's COPY command does not seem to understand symlinks so instead makes two complete copies of the library files. This results in a larger Docker Image size and warnings from later apt-get commands to the tune of ldconfig: /usr/local/lib/libprotobuf.so.17 is not a symbolic link.

目前我的特定文件如下:

My specific file presently looks like:

#Compile any tools we cannot install from packages
FROM gcc:7 as builder
USER 0
RUN \
  apt-get -y update && \
  apt-get -y install \
    clang \
    libc++-dev \
    libgflags-dev \
    libgtest-dev
RUN \
  # Protocol Buffer & gRPC
  # install protobuf first, then grpc
  git clone -b $(curl -L https://grpc.io/release) \
      https://github.com/grpc/grpc /var/local/git/grpc && \
    cd /var/local/git/grpc && \
    git submodule update --init && \
    echo "--- installing protobuf ---" && \
    cd third_party/protobuf && \
    ./autogen.sh && ./configure --enable-shared && \
    make -j$(nproc) && make install && make clean && ldconfig && \
    echo "--- installing grpc ---" && \
    cd /var/local/git/grpc && \
    make -j$(nproc) && make install && make clean && ldconfig


FROM debian
LABEL \
 Description="Basic Debian production environment with a number of libraries configured" \
 MAINTAINER="Mr Me"
ARG prefix=/usr/local
ARG binPath=$prefix/bin
ARG libPath=$prefix/lib
# Copy over pre-made tools
# Protocol Buffer
COPY --from=builder /usr/local/lib/libproto* $libPath/
# gRPC
COPY --from=builder /usr/local/lib/libaddress_sorting.so.6.0.0 $libPath/
COPY --from=builder /usr/local/lib/libgpr* $libPath/
COPY --from=builder /usr/local/lib/libgrpc* $libPath/
RUN ldconfig
# Install remaining tools using apt-get
RUN apt-get -y update && \
  apt-get -y install \
    libhdf5-dev \
    libssl1.1 \
    uuid-dev;

如您所见,我正在尝试将最新版本的gRPC和Protocol Buffer添加到基于Debian的运行时映像。

As you can see I am trying to add the latest versions of gRPC and Protocol Buffer to a Debian based runtime image.

推荐答案

这比解决方案更能解决问题。

This is more of a workaround than an answer.

您可以将文件压缩,将压缩包复制到第二个容器中,然后将其解压缩。

You could tar the files, copy the tarball to the second container and then untar them.

Tar 默认情况下保持符号链接

这篇关于如何在保留符号链接的同时在多阶段Docker构建的各个阶段之间复制库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆