0

I want to run a Python script from a Docker container that has dependencies set using Conda, i.e.:

Dockerfile:

FROM continuumio/miniconda3

ADD environment.yml /environment.yml

RUN conda env create -f /environment.yml
# Pull the environment name out of the environment.yml
RUN echo "source activate $(head -1 /environment.yml | cut -d' ' -f2)" > ~/.bashrc
ENV PATH /opt/conda/envs/$(head -1 /environment.yml | cut -d' ' -f2)/bin:$PATH

ADD hello.py /

CMD ["python", "./hello.py" ]

The environment.yml contains all the dependencies and the python script for now it is just a hello world:

import zeep


print("hello")

But when running the container I get:

⇒  docker run  hello
Traceback (most recent call last):
  File "./hello.py", line 1, in <module>
    import zeep
ModuleNotFoundError: No module named 'zeep'

Why is that? If I start it interactively I can run the script fine.

⇒  docker run -it hello /bin/bash
(smoke-test) root@1c593ac836b0:/# python hello.py
hello
void
  • 1,484
  • 1
  • 15
  • 18
  • (Don't try to set `.bashrc` in a Dockerfile: `docker run hello`, for instance, will just go off and run `hello` without involving a shell. I'm pretty sure the `ENV ...$(...)...` syntax won't work, Docker only does straight-up string interpolation in Dockerfiles.) – David Maze Nov 17 '18 at 11:29
  • Thanks @David Maze, yes, same issue. It is a bit annoying to be honest, I'll switch back to pip then. Thanks for your response. – void Nov 18 '18 at 16:45

0 Answers0