s_ammazzalorso
s_ammazzalorso

Reputation: 11

Problems in activating conda enviroment in docker

I would like to set permanently a conda environment in my docker image in order that the functions of the conda package could be used by the script given as argument to the entrypoint. This is the dockerfile that I created.

FROM continuumio/anaconda3

RUN conda create -n myenv
RUN echo "source activate myenv" > ~/.bashrc
ENV PATH:="/opt/conda/envs/myenv/bin:$PATH"
SHELL ["/bin/bash", "-c"]

ENTRYPOINT ["python3"]

It seems that the ~/.bashrc file is not sourced when I run the docker container. Am I doing something wrong?

Thank you

Upvotes: 1

Views: 340

Answers (1)

Michael Conrad
Michael Conrad

Reputation: 180

As a work around either use 'SHELL ["/bin/bash", "-i", "--login", "-c"]'

-or-

edit the .bashrc file in the image to not exit if not in interactive mode by changing "*) return;;" to read "*) ;;"

Using the first option bash will complain about job control and ttys, but the error can be ignored.

cause of the issue:

the .bashrc file contains the following command:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

which causes bash to stop sourcing the file if not in interactive mode. (the -i flag)

Unfortunately, I haven't found a way for the conda stanza to be inserted into .bash_profile or .profile automatically instead of (or in addition to) .bashrc, as there doesn't seem to be an option to override or add to the list of what files conda init examines for modification.

Upvotes: 1

Related Questions