use makefile to copy files in docker multi-stage builds

Solution 1:

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?

Solution 2:

./configure --prefix=/path/to/somewhere will force make install to deploy all files under /path/to/somewhere

So it is easy to copy all files from this place in the second stage.