0

I try to create a new anaconda environment inside docker. I get an error message I cannot get rid of. What I do in my Dockerfile is:

FROM postgis/postgis:12-master
ENV BAG_ENV=bag
RUN wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh --quiet -O /tmp/anaconda.sh
RUN /bin/bash /tmp/anaconda.sh -b -p /opt/conda
RUN conda update conda
RUN conda init bash
RUN . /opt/conda/etc/profile.d/conda.sh
RUN conda create --name $BAG_ENV --force -y python=3.8.2 pip conda libxml2 lxml gdal psycopg2 
RUN conda activate $BAG_ENV

I have the same error when running similar instructions from a bash script. The error I get is:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

From this link I learned to source conda.sh. This works for my bash script but not in my Dockerfile. How can I solve this problem?

I run this from an Ubuntu 20.04 machine, the Dockerfile is derived from alpine.

Arnold
  • 4,578
  • 6
  • 52
  • 91
  • 1
    Each `RUN` command runs in its own shell (and its own container!) so when you `RUN conda init`, any environment variables it sets are lost on the next `RUN` command. Can you use a simpler Python setup, based on a `Pipfile` or `requirements.txt` file, that wouldn't require special environment setup? Can you use a standard Python base image rather than a PostGIS database image? – David Maze May 06 '21 at 10:14
  • Thanks for your explanation, i didn't know this thing about RUN. I need postgis, but I'll try to run everything from the base environment now. Thanks for your help! – Arnold May 06 '21 at 10:30

0 Answers0