Last active
June 27, 2018 12:39
-
-
Save aharonamir/bf8ffae7539786d5d32ee5735bfa5cc5 to your computer and use it in GitHub Desktop.
Multi-Stage Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MULTI STAGE BUILD | |
# start from building develop image | |
# and then run the compile | |
FROM aharonamir/dev-cpp:4.9 as builder | |
# install project specific dependencies | |
USER root | |
COPY ./dependencies/install-dependencies.sh /usr/ | |
RUN chmod +x /usr/install-dependencies.sh | |
RUN apt-get update | |
RUN /usr/install-dependencies.sh | |
# Clean up APT when done. | |
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
#copy all the code : use .dockerignore for unwanted files | |
WORKDIR /home/develop/project | |
COPY . /home/develop/project/ | |
# compile link and copy the bin with dependencies to /tmp/ | |
# we need to do it as one RUN command since the products of the workdir are temp | |
# for this intermediate container (layer) | |
RUN cmake . \ | |
&& make \ | |
&& mkdir -p /tmp/dist \ | |
&& mkdir -p /tmp/app \ | |
&& cp `ldd build/bin/your_app | grep -v nux-vdso | awk '{print $3}'` /tmp/dist/ \ | |
&& cp build/bin/your_app /tmp/app/ | |
# now start from a lean image and copy all the needed bin/libs only | |
FROM ubuntu:xenial | |
# app | |
COPY --from=builder /tmp/dist/* /usr/lib/x86_64-linux-gnu/ | |
COPY --from=builder /tmp/app/your_app /usr/ | |
WORKDIR /usr | |
ENTRYPOINT ["./your_app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment