I’m using nipype as a starting point to familiarize myself with Docker image creation. The end goal is to create images for a workshop I’m running this summer.
I’m going through the documentation on repronim, and a lot of things aren’t working. Maybe I can contribute at some point by submitting pull requests or something. In the mean time, I’m just trying something fairly basic to start with.
neurodocker generate docker \
--pkg-manager apt \
--base debian:buster-slim \
--miniconda \
create_env=jupyter \
version=latest \
conda_install="matplotlib notebook numpy pandas seaborn" \
--user nonroot \
--workdir /work \
> notebook.Dockerfile
One problem was that --base-image is now --base. Got that.
According to docker scan, there are lots of vulnerabilities with buster, but rolling with that now to simplify.
Now --miniconda
wants either create_env
or use_env
. I went with create_env
, and named it jupyter
.
When I build the image, it seems to install everything in that environment as expected.
docker build --tag notebook --file notebook.Dockerfile .
However, using that environment when trying to run Jupyter Notebook has me stumped. Just for completeness, here’s my run command line.
docker run --rm -it --workdir /work --volume $PWD:/work --publish 8888:8888 --ip 0.0.0.0 notebook jupyter-notebook
If I run a bash
shell in the container, I can’t activate the environment because .bashrc hasn’t been set up. So I conda init bash
, then source /home/nonroot/.bashrc
, then I can conda activate jupyter
and it will run.
So the problem is, how do I conda init bash
when creating the image, then conda activate jupyter
when the image is run?
I’ve tried this in the first RUN in the Dockerfile:
&& echo 'set -e' >> "$ND_ENTRYPOINT" \
&& echo 'export USER="${USER:=`whoami`}"' >> "$ND_ENTRYPOINT" \
&& echo 'conda init bash' >> "$ND_ENTRYPOINT" \ # added this
&& echo 'source $HOME/.bashrc' >> "$ND_ENTRYPOINT" \ # added this
&& echo 'conda activate jupyter' >> "$ND_ENTRYPOINT" \ # added this
&& echo 'if [ -n "$1" ]; then "$@"; else /usr/bin/env bash; fi' >> "$ND_ENTRYPOINT"; \
Since I’m posting here, you probably suspect this doesn’t work, and you would be right.
It looks like the conda init bash
runs, as I see that /home/nonroot/.bashrc
has been modified, but when activate runs, it says the shell has not been initialized.
Questions:
- Am I missing an updated procedure somewhere?
- Can I use
neurodebian:bullseye
which seems to be more secure? - How can I create,
conda init
andconda activate
an environment? - Can I use the same procedures (whatever those might be) to create the full nipype image as is done here?
Thanks!