Search code examples
dockerdockerfiledocker-multi-stage-build

Multi-stage build just loading last part?


I'm new with docker and I'm pretty sure this must be a silly mistake (sorry in advance), but I'm trying to combine some images. The first one is to install a software (TEtranscripts), and the second one I just want to have it as it is (cellranger). Here is my Dockerfile:

FROM continuumio/anaconda
RUN conda install -c bioconda tetranscripts

FROM marcusczi/cellranger_clean
COPY --from=marcusczi/cellranger_clean / /

I don't get any errors when building this (docker build --tag tecell .), but when i run it (docker run -i -t --name tecell tecell) only cellranger is available. If i switch places like:

FROM marcusczi/cellranger_clean
COPY --from=marcusczi/cellranger_clean / /

FROM continuumio/anaconda
RUN conda install -c bioconda tetranscripts

Just TEtranscripts is available.

I was checking the official tutorial about it and I notice they built the app before passing to the next FROM statement, so I'm guessing is something like that but I would like some explanation on how/why to use it.

Thank you so much in advance! :-)


Solution

  • Your COPY --from is wrong. You should reference the other build-step instead.

    Like that: FROM continuumio/anaconda as firststep and COPY --from=firststep

    So your Dockerfile should be:

    FROM continuumio/anaconda as firststep
    RUN conda install -c bioconda tetranscripts
    
    FROM marcusczi/cellranger_clean
    COPY --from=firststep / /