Automate adding .condarc (for nb_conda_kernels) to Dockerfile

Hello, I have been following this documentation to allow users to create custom conda environments.

Part of my Dockerfile has this:

WORKDIR $HOME

USER root

# Create a folder of conda environments in the user's directory
RUN conda config && \
    echo "envs_dirs:" > $HOME/.condarc && \
    echo "  -/home/jovyan/my-conda-envs/" >> $HOME/.condarc

However, .condarc and the folder my-conda-envs is not created. If I run these commands in the JupyterHub itself, I am able to create these. Is there a way to run these commands automatically via a Dockerfile?

I also tried adding this to config.yaml, but it also does not create .condarc.

    lifecycleHooks:
      postStart:
        exec:
          command: ["conda", "config"]
          command: ["echo", "'env_dirs'", ">", "~/.condarc"]
          command: ["echo", "'  -home/jovyan/my-conda-envs/'", ">>", "~/.condarc"]

I thought this would work since the commands should run each time a user starts a server. An approach like this is less desirable though since it would overwrite .condarc each time a server starts.

Any update on how the .condarc file was created in the /home/jovyan with the "/my-conda-envs"directory?

Thanks,

Unfortunately, I was not able to get it working and I haven’t looked into the issue since. :frowning: Have you had any luck?

I was not able to copy the .condarc file but was make the .local directory persistent so that I can download all my python site-packages under .local. If I logout and login, I am able to find my downloaded python packages. This is one way I got the downloaded packages to be persistent. There could be a better way using .condarc as documented but I could get that to work.