Can't recreate Conda environment in docker

Viewed 1484

I created a conda environment from a fresh installation of miniconda3.

After that I exported it and this is the content of the file (my only extra install was flask):

name: myenv
channels:
  - defaults
dependencies:
  - ca-certificates=2018.03.07=0
  - certifi=2018.11.29=py37_0
  - click=7.0=py37_0
  - flask=1.0.2=py37_1
  - itsdangerous=1.1.0=py37_0
  - jinja2=2.10=py37_0
  - libcxx=4.0.1=hcfea43d_1
  - libcxxabi=4.0.1=hcfea43d_1
  - libedit=3.1.20170329=hb402a30_2
  - libffi=3.2.1=h475c297_4
  - markupsafe=1.1.0=py37h1de35cc_0
  - ncurses=6.1=h0a44026_1
  - openssl=1.1.1a=h1de35cc_0
  - pip=18.1=py37_0
  - python=3.7.1=haf84260_7
  - readline=7.0=h1de35cc_5
  - setuptools=40.6.2=py37_0
  - sqlite=3.26.0=ha441bb4_0
  - tk=8.6.8=ha441bb4_0
  - werkzeug=0.14.1=py37_0
  - wheel=0.32.3=py37_0
  - xz=5.2.4=h1de35cc_4
  - zlib=1.2.11=h1de35cc_3
prefix: /Users/rossid/miniconda3/envs/phadmin

now what I want, is to recreate this environment in a docket image so I created this Dockefile

FROM continuumio/miniconda3
ADD * myappdir/
RUN conda env create -f /myappdir/environment.yml

but it will fail with:

Step 1/5 : FROM continuumio/miniconda3
 ---> d3c252f8727b
Step 2/5 : ADD * myappdir/
 ---> Using cache
 ---> 2afbf5ea75bd
Step 3/5 : RUN conda env create -f /myappdir/environment.yml
 ---> Running in 7f916bd46979
Solving environment: ...working... failed

ResolvePackageNotFound: 
  - tk==8.6.8=ha441bb4_0
  - ncurses==6.1=h0a44026_1
  - markupsafe==1.1.0=py37h1de35cc_0
  - readline==7.0=h1de35cc_5
  - zlib==1.2.11=h1de35cc_3
  - openssl==1.1.1a=h1de35cc_0
  - xz==5.2.4=h1de35cc_4
  - libcxxabi==4.0.1=hcfea43d_1
  - libcxx==4.0.1=hcfea43d_1
  - libffi==3.2.1=h475c297_4
  - sqlite==3.26.0=ha441bb4_0
  - python==3.7.1=haf84260_7
  - libedit==3.1.20170329=hb402a30_2

why is this happening? If I try to do the same to create another environment it works. If I remove the build version, some dependencies are resolved (I mean the third coordinate in dependencies).

I tried to add more channels like conda-forge, but nothing.

Also my .condarc file is empty.

Does anyone know how to fix this?

1 Answers

I had a similar problem and I find multiple ways to solve it. The main problem with your approach is conda is not platform independent, so will force the environments to use pip.

1. Conda Like Solution

Change your my_env.yml so that all the dependencies apart from pip goes under the pip dependency. Notice that the syntax is different when you move under the pip.

For instance:

name: myenv
channels:
  - defaults
dependencies:
   - pip=18.1
   - pip:
     - wheel==0.32.3

Then go to your Dockerfile and add the following line:

RUN conda env update -n base --file myenv.yml

2. Good old Pip way

Export your conda environment into a pip requirements file as at this answer

conda install pip
pip freeze > requirements.txt

Then go to your Docker file and add the following line:

RUN python -m pip install -r requirements.txt
Related