Open traversaro opened 1 year ago
You can take inspiration from the Docker image I'm using for my day-to-day development for few years now: diegoferigo/development-iit@Conda.
In particular, these lines create a default environment with micromamba
.
The main trick to enable the environment in the rest of the Dockerfile (and I mean, in the build stage) is the combination of:
/etc/bash.bashrc
file.bash
as shell during docker build as opposed to sh
, performed in this line.With this trick, every RUN
command is executed in bash
, that sources the file /etc/bash.bashrc
that in turn it enables the conda environment.
To include also alumnis, I guess also @prashanthr05 may have useful pointers.
I have used what @traversaro has already mentioned in https://github.com/ami-iit/ami-commons/issues/5#issue-1531974087 as a reference to run conda and Docker and additionally took a lot of inspiration from @diegoferigo's repository https://github.com/diegoferigo/development-iit and @GiulioRomualdi's repository https://github.com/ami-iit/paper_romualdi_2022_icra_centroidal-mpc-walking to install all the necessary robotology-superbuild based dependencies using conda and self-activated conda environment at every docker run in https://github.com/ami-iit/paper_ramadoss_2022_humanoids_human-base-estimation.
But while cleaning up the conda installation for slimming down the images, it is better to keep an eye on what are we deleting to keep the image light, see issue https://github.com/prashanthr05/sample-docker-conda-cpp-project/issues/1#issuecomment-1283744226.
Some other useful resources to read through to keep images small, reduce build times, and an ounce of security while using Docker containers are mentioned in the following articles,
C.C. @mebbaid
This seems to be important for many in @ami-iit/artificial-mechanical-intelligence dealing with Docker
With @GiulioRomualdi and @CarlottaSartore, we had the doubt of the proper way of setting up a Docker image in a way that new commands "saw" the environment. Initially we followed https://pythonspeed.com/articles/activate-conda-dockerfile/, but the suggestion of using
conda run
was problematic as anyCOMMAND
statement needed to be prefixed byconda run
.So, I think instead a good source of inspiration may be https://github.com/conda-forge/miniforge-images, that contains the Dockerfiles for the images published for example in https://hub.docker.com/r/condaforge/mambaforge . If feasible, it can make sense to use
condaforge/mambaforge
as a base image, while if that is not possible and you want to install conda/mamba manually it is a good idea to check how they do it in https://github.com/conda-forge/miniforge-images/blob/master/ubuntu/Dockerfile:It seems that the script is quite self-explanatory, in particular that in the activation script
conda activate base
should be prefixed by. ${CONDA_DIR}/etc/profile.d/conda.sh &&
.Once you have something that is working and you want to reduce its size, you can also check https://jcristharif.com/conda-docker-tips.html for additional tricks.