ReproNim / neurodocker

Generate custom Docker and Singularity images, and minimize existing containers
https://www.repronim.org/neurodocker/
Apache License 2.0
330 stars 97 forks source link

Error using neurodocker reprozip #219

Closed xaviergp closed 6 years ago

xaviergp commented 6 years ago

Hi! I am trying to minimize a neurodocker container using neurodocker reprozip. My container uses fsl, freesurfer, and HCPworkbench. I have a python script that takes a nifti file from the container and does some fsl, freesurfer, and HCPworkbench operations.

I do this: docker run --rm -itd --entrypoint bash --security-opt=seccomp:unconfined --name minify19 xaviergp/gradmap_forreprozip Then this: neurodocker reprozip trace -v debug minify19 "python3 /src/gradmap_v1/toolbox_forreprozip.py"

I get this error, which does not appear when I run my container normally: [NEURODOCKER 2018-08-14 10:45:09,092 DEBUG]: ERROR:: Environment variable FSLOUTPUTTYPE is not set! [NEURODOCKER 2018-08-14 10:45:09,092 DEBUG]: Please make sure that the appropriate configuration file is sourced by your shell (e.g. by putting it in .profile). [NEURODOCKER 2018-08-14 10:45:09,092 DEBUG]: e.g. bash or sh users add the line ". ${FSLDIR}/etc/fslconf/fsl.sh" [NEURODOCKER 2018-08-14 10:45:09,093 DEBUG]: e.g. tcsh or csh users add the line "source ${FSLDIR}/etc/fslconf/fsl.csh"

Do you know what may be causing this? Thank you, Xavier.

kaczmarj commented 6 years ago

@xaviergp - how did you install fsl? did you use --install fsl or something similar? the issue is

Environment variable FSLOUTPUTTYPE is not set

if you tell me how you installed fsl, i can show you how to run the fsl.sh config script that will set important environment variables.

xaviergp commented 6 years ago

Hi Jakub, This is the full list of commands I used to build the neurodocker container:

docker.exe run --rm kaczmarj/neurodocker:master generate "docker" \ --base=neurodebian:stretch-non-free \ --pkg-manager=apt \ --install connectome-workbench \ --freesurfer version=6.0.0-min\ --fsl version=5.0.11\ --miniconda create_env=neuro \ conda_install="python=3.6 numpy seaborn nibabel jupyter nilearn" activate=true \ pip_install="https://github.com/mgxd/niwidgets/archive/fix/inst.zip" \ --workdir='/src' \ --user root \ --run "wget --output-document=gradmap.tar.gz https://www.dropbox.com/s/qrosgd80qrg9eiy/gradmap.tar.gz?dl=1 && tar -xvf gradmap.tar.gz && rm gradmap.tar.gz" \ --add-to-entrypoint="bash" \ --run "mv /src/gradmap_v1/license.txt /opt/freesurfer-6.0.0-min/" > dockerfile

docker.exe build -t gradmap_neurodocker_v21 .

I pushed the container to dockerhub as xaviergp/gradmap_forreprozip, and then did this:

docker run --rm -itd --entrypoint bash --security-opt=seccomp:unconfined --name minify19 xaviergp/gradmap_forreprozip

neurodocker reprozip trace -v debug minify19 "python3 /src/gradmap_v1/toolbox_forreprozip.py"

kaczmarj commented 6 years ago

Ok, when you run the container (before the trace), do not set the entry point as bash. Use the default entry point. That will source the correct environment variables.

On Aug 14, 2018, at 11:54 AM, Xavier Guell notifications@github.com wrote:

Hi Jakub, This is the full list of commands I used to build the neurodocker container:

docker.exe run --rm kaczmarj/neurodocker:master generate "docker" --base=neurodebian:stretch-non-free --pkg-manager=apt --install connectome-workbench --freesurfer version=6.0.0-min --fsl version=5.0.11 --miniconda create_env=neuro conda_install="python=3.6 numpy seaborn nibabel jupyter nilearn" activate=true pip_install="https://github.com/mgxd/niwidgets/archive/fix/inst.zip" --workdir='/src' --user root --run "wget --output-document=gradmap.tar.gz https://www.dropbox.com/s/qrosgd80qrg9eiy/gradmap.tar.gz?dl=1 && tar -xvf gradmap.tar.gz && rm gradmap.tar.gz" --add-to-entrypoint="bash" --run "mv /src/gradmap_v1/license.txt /opt/freesurfer-6.0.0-min/" > dockerfile

docker.exe build -t gradmap_neurodocker_v21 .

I pushed the container to dockerhub as xaviergp/gradmap_forreprozip, and then did this:

docker run --rm -itd --entrypoint bash --security-opt=seccomp:unconfined --name minify19 xaviergp/gradmap_forreprozip

neurodocker reprozip trace -v debug minify19 "python3 /src/gradmap_v1/toolbox_forreprozip.py"

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

xaviergp commented 6 years ago

Hi Jakub, I modified the commands as follows, but still get the same error

docker.exe run --rm kaczmarj/neurodocker:master generate "docker" --base=neurodebian:stretch-non-free --pkg-manager=apt --install connectome-workbench --freesurfer version=6.0.0-min --fsl version=5.0.11 --miniconda create_env=neuro conda_install="python=3.6 numpy seaborn nibabel jupyter nilearn" activate=true pip_install="https://github.com/mgxd/niwidgets/archive/fix/inst.zip" --workdir='/src' --user root --run "wget --output-document=gradmap.tar.gz https://www.dropbox.com/s/qrosgd80qrg9eiy/gradmap.tar.gz?dl=1 && tar -xvf gradmap.tar.gz && rm gradmap.tar.gz" --run "mv /src/gradmap_v1/license.txt /opt/freesurfer-6.0.0-min/" > dockerfile

docker.exe build -t gradmap_neurodocker_v21 .

I pushed the container to dockerhub as xaviergp/gradmap_forreprozip, and then did this:

docker run --rm -itd --security-opt=seccomp:unconfined --name minify20 xaviergp/gradmap_forreprozip

neurodocker reprozip trace -v debug minify20 "python3 /src/gradmap_v1/toolbox_forreprozip.py"

ERROR: [NEURODOCKER 2018-08-14 17:27:37,009 DEBUG]: ERROR:: Environment variable FSLOUTPUTTYPE is not set! Please make sure that the appropriate configuration file is sourced by your shell (e.g. by putting it in .profile). [NEURODOCKER 2018-08-14 17:27:37,009 DEBUG]: e.g. bash or sh users add the line ". ${FSLDIR}/etc/fslconf/fsl.sh" [NEURODOCKER 2018-08-14 17:27:37,009 DEBUG]: e.g. tcsh or csh users add the line "source ${FSLDIR}/etc/fslconf/fsl.csh"

kaczmarj commented 6 years ago

i think i figured it out. certain environment variables are not persisting during the reprozip trace (namely the environment variables from fsl.sh.

what you have to do in this case is add os.environ["FSLOUTPUTTYPE"] = "NIFTI_GZ" towards the top of your script (but below import os).

this worked for me on linux. please let me know if it doesn't work for you. it looks like the minimized container will be around 150-200 MB.

xaviergp commented 6 years ago

It works, thanks!