大网数据广告活动
服务器运维问答

use makefile to copy files in docker multi-stage builds

· 52CE 我爱测

I'm using multi-stage builds to separate the build environment from the final docker image: FROM ubuntu:bionic AS build RUN apt-get update && apt-get install -y \ build-essential \ [...] RUN wget https://someserver.com/somefile.t…

问题原文

原帖链接 · sc911 · CC BY-SA 4.0

I'm using multi-stage builds to separate the build environment from the final docker image:

FROM ubuntu:bionic AS build
RUN apt-get update && apt-get install -y \
    build-essential \
    [...]
RUN wget https://someserver.com/somefile.tar.gz && \
    tar xvzf somefile.tar.gz && \
    ./configure && \
    make && make install && \
    [missing part]

FROM ubuntu:bionic
COPY --from=build /tmp/fakeroot/ /
[...]

Is there an easy way to collect all files that where created/copied while make install was running?

Currently I'm using a combination of ldd and individual file copy to get them all:

cp /etc/xyz/* /tmp/fakeroot/xyz
cp --parents $(ldd /usr/sbin/nginx | grep -o '/.\+\.so[^ ]*' | sort | uniq) /tmp/fakeroot

But as make install already has the information of which file to copy to what directory I'm asking myself if there isn't any way to use this mechanism.

Thanks for any ideas!

已采纳解答

原帖链接 · sc911 · CC BY-SA 4.0

One way I found now is using checkinstall which replaces the make install step and tracks the installation to produce a package in the first stage. Then in the second stage I'm using dpkg to install this package.

So now I'm doing:

FROM ubuntu:bionic AS build
RUN [...]
    ./configure && \
    make && \
    checkinstall --install=no --default && \
    cp XYZ-*.deb /XYZ.deb

FROM ubuntu:bionic
COPY --from=build /XYZ.deb /
RUN dpkg -i /XYZ.deb && \
    rm /XYZ.deb && \
    [...]

Any downsides of this approach?

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。