Testing how to properly set up a Dockerfile to use python libraries installed from source.
Build an image from a Dockerfile.
You need to specify the path .
and you can also set the image name with -t
docker build . -t test
Run an image, setting the container name, running a bash interactively and removing the container after the execution.
You can set the option -d
(detach) to run it on the background.
docker run --name test --rm -it test bash
Starts a generated container and run it interactively.
docker start -i test
Stops a running container.
docker stop test
-
Qibo library requires
scipy
,numpy
andmatplotlib
. Those libraries are not possible to be installed usingpip
on an ARM Apple chip, and requires to be installed usingconda
fromminiconda
. -
There are a few pre-built docker images containing
miniconda
, the best one seems to be continuumio/miniconda3. Although on their github exists the alpine version of it, the one you pull from it, it is a debian-based image. The thing with this one is that you cannot install any other system library (but you can install any python library indeed), as the user is non-root. In my case, I need to install some other system packages, so it is not a suitable option for me. -
Another option is bulding the same image on your own. I tried to do that with the alpine version, but did not succeed. Conda uses glibc, and you need then to either install it on your own, or use a pre-built image with glibc installed. My code requires python 3.9 because I am using typings, so I need to take this into account when installing my own conda version to properly download one compatible with python 3.9.
-
So, when following the
continuumio
docker steps to build the glibc, it raises an error because it cannot find the generated libraries. I tried a few times but I did not find the proper solution. Then, I decided to use another prebuilt image with glibc installed from frolvlad/alpine-glibc, and using thecontinuumio
instructions to installconda
in it, using theCONDA_VERSION=py_39_4.10.3
and itssha256sum
. -
Just make sure to set the
PATH
variable withconda
andbin
directories, and initializingconda
:
ENV PATH /bin:/sbin:/usr/bin:$PATH
ENV PATH /opt/conda/bin:$PATH
RUN conda init
- You can then install the required packages:
scipy
,numpy
, andmatplotlib
usingconda
.
RUN conda install scipy numpy matplotlib
- And finally you can install
qibo
RUN pip install qibo