0

I have one Dockerfile that looks like this:

FROM python:3.10.9
COPY ./env.yml .
RUN apt-get update && \
    apt-get install -y wget bzip2 && \
    wget -q https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh -O /tmp/anaconda.sh && \
    /bin/bash /tmp/anaconda.sh -b -p /opt/conda && \
    rm /tmp/anaconda.sh \
    conda env create -f env.yml
CMD ["conda", "activate", "env"]

Let's call this Docker A. We build it as such: docker build -t docker_a -f ./docker_a.dockerfile ..

Another Dockerfile that we'll call Docker B look like this:

FROM docker_a:latest
COPY ./file1.json ./file2.csv ./run_script.sh ./
RUN conda activate env
CMD ["run_script.sh", "1"]

When I run this I get a /bin/sh: 1: conda: not found error. I figure that the virtual environment I created in Docker A isn't being properly propagated to Docker B.

How do I connect the two?

For some context, I'll be using several Docker images like these inside of a KubeFlow Pipeline.

Sean
  • 2,890
  • 8
  • 36
  • 78
  • `RUN conda activate` doesn't persist beyond the current `RUN` line; you'd have the same problem if you combined these two Dockerfiles into one. Does one of the approaches in [Activate conda environment in docker](https://stackoverflow.com/questions/55123637/activate-conda-environment-in-docker) help you? The Dockerfile structure itself seems fine. If it's a choice to directly use Python and `pip install` packages into the "system" Python without using Conda or a virtual environment, that would also avoid this problem. – David Maze Apr 27 '23 at 10:12

0 Answers0