Docker Community Forums

Share and learn in the Docker community.

Combining two dockerfiles

Hello there, I am fairly new to dockerfiles and want to “combine” two docker files. The reason is that I need packages from the first dockerfile in the second container but I have trouble getting it to work.

Both docker containers work fine on their own but that is of no use sadly ;(

Dockerfile 1 (main dockerfile for my backend):

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7


# Install Poetry
RUN curl -sSL | POETRY_HOME=/opt/poetry python && \
    cd /usr/local/bin && \
    ln -s /opt/poetry/bin/poetry && \
    poetry config virtualenvs.create false

# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./app/pyproject.toml ./app/poetry.lock* /app/

# Allow installing dev dependencies to run tests
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"

# For development, Jupyter remote kernel, Hydrogen
# Using inside the container:
# jupyter lab --ip= --allow-root --NotebookApp.custom_display_url=
RUN bash -c "if [ $INSTALL_JUPYTER == 'true' ] ; then pip install jupyterlab ; fi"

COPY ./app /app

Dockerfile 2 (contains the qiime package that I need in the backend):

FROM continuumio/miniconda3


ENV PATH /opt/conda/envs/qiime2-${QIIME2_RELEASE}/bin:$PATH
ENV HOME /home/qiime2

RUN mkdir /home/qiime2
WORKDIR /home/qiime2

RUN conda update -q -y conda
RUN conda install -q -y wget
RUN apt-get install -y procps
RUN wget${QIIME2_RELEASE}-py38-linux-conda.yml
RUN conda env create -n qiime2-${QIIME2_RELEASE} --file qiime2-${QIIME2_RELEASE}-py38-linux-conda.yml
RUN rm qiime2-${QIIME2_RELEASE}-py38-linux-conda.yml
RUN /bin/bash -c "source activate qiime2-${QIIME2_RELEASE}"
RUN qiime dev refresh-cache
RUN echo "source activate qiime2-${QIIME2_RELEASE}" >> $HOME/.bashrc
RUN echo "source tab-qiime" >> $HOME/.bashrc

Since both Dockerfiles use a different base image, you will need to pick one as your new base image and add everything from the other image and its base image (if it uses a base image itself, then from this base image as well, until you reach a “pure” os image) additionaly to your Dockerfile.

Hope the result is not too messy…

If i’d be you, Id start with a python base image and all dependencies to the Dockerfile myself… seems cleaner to me.