I have a docker container (running Ubuntu) with conda (miniconda) installed. I can create new conda environments in the container but they will not persist the next time I create a new container. I don’t want to install the packages as part of the Docker image, so what is the best way to make install packages persist in the container? I imagine some directory needs to be mounted on the host so any conda install
command installs packages on a host directory and is there the next time a new container is spawned.
2
Answers
The following two locations need to be mounted from outside of the container to make sure conda environment packages don't get removed between container runs:
1. Create directories for python packages outside of container
2. Mount conda env and pkgs directories
Now any packages installed in the conda environment via
pip
orconda install
will persist when the container is exited.The best way actually would be to create your own image with the required
conda
environment already pre-installed.This is because
docker
containers are meant to be ephemeral, i.e., stopping and removing a container will also throw away any changed state in it and you should be able to just start a new container from the same image.To store persistent data you have to use
volumes
orbind-mounts
, see thedocker
storage docs on this: https://docs.docker.com/storage/In your case you would have to add one or multiple
volumes
to your container and place any changed/installed files there.