Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem building image from BIDS/example #295

Closed
mathdugre opened this issue Aug 14, 2019 · 8 comments
Closed

Problem building image from BIDS/example #295

mathdugre opened this issue Aug 14, 2019 · 8 comments

Comments

@mathdugre
Copy link

I am trying to minify the size of BIDS/example however I am running into some errors.

I used the bids app example with the corr/IPCAS_4 (BIDS) dataset.

Normal MWE

# Generate image from bids/example
$ neurodocker generate docker -b bids/example -p apt > Dockerfile
$ docker build -t bids-example .

# Start a container
$ docker run --rm -itd -v $PWD/data:/data -v $PWD/outputs:/outputs --name bids-example --security-opt=seccomp:unconfined bids-example

# Execute command in the container
$ cmd1='python3 /run.py /data/IPCAS_4 /outputs participant --participant_label 0026190'
$ cmd2='python3 /run.py /data/IPCAS_4 /outputs group'
$ neurodocker reprozip trace bids-example "$cmd1" "$cmd2"

# Build image from reprozip file
reprounzip docker setup neurodocker-reprozip.rpz img

However when using reprounzip I have this error:

Step 6/6 : RUN     chmod +x /busybox /rpzsudo &&     cd / && (tar zpxf /reprozip_data.tgz -U --recursive-unlink --numeric-owner --strip=1 --null -T /rpz-files.list || /busybox echo "TAR reports errors, this might or might not prevent the execution to run")
 ---> Running in 0c770eeaff35
tar: etc: Cannot unlink: Device or resource busy
tar: etc/resolv.conf: Cannot unlink: Device or resource busy
tar: Exiting with failure status due to previous errors
TAR reports errors, this might or might not prevent the execution to run

I tried to launch the image interactively afterwards but the tool remove file to much (e.g. bahs was gone)

ndminify MWE

I then tried a modified (and less aggressive version of the tool) #258.

When using this version starting from the previous bids-example container I get:

# Specify commands to run
$ cmd0='mkdir /test' # dummy folder to remove
$ cmd1='touch /test/file'
$ cmd2='python3 /run.py /data/IPCAS_4 /outputs participant --participant_label 0026190'
$ cmd3='python3 /run.py /data/IPCAS_4 /outputs group'

# Execute command with ndminify
ndminify -c bids-example -d /test --commands "$cmd0" "$cmd1" "$cmd2" "$cmd3"

When using this version of the tool, I get errors due to bet not being installed in the final image.

@kaczmarj
Copy link
Collaborator

hi @mathdugre - thank you for the report. minimizing containers is still a finicky process. i'm a bit backed up at the moment with other tasks, but i will look into this soon. thanks for the details you provided.

before i can get to this, can you please answer these questions?

  • does reprounzip docker setup neurodocker-reprozip.rpz img produce a Docker image named img?
  • if it does, can you enter the image and try to find the bet program? It should be in /usr/lib/fsl/5.0 but it could be somewhere else in the directory structure.

thanks.

one note: the lines

$ neurodocker generate docker -b bids/example -p apt > Dockerfile
$ docker build -t bids-example .

are not necessary. you can simply use the bids/example docker image as normal (i.e., docker run bids/example ...). the neurodocker generate ... command you wrote does not really add anything to the bids/example image.

@mathdugre
Copy link
Author

Hi @kaczmarj - thank you for your help. Using the steps you described above an image with the name "reprounzip_image_wh4z5aenyn" and I couldn't find bet in /usr/lib/fsl/5.0/bet or /usr/share/fsl/5.0/bin/bet.

When executing reprounzip docker setup neurodocker-reprozip.rpz img I am still getting this error:

Step 6/6 : RUN     chmod +x /busybox /rpzsudo &&     cd / && (tar zpxf /reprozip_data.tgz -U --recursive-unlink --numeric-owner --strip=1 --null -T /rpz-files.list || /busybox echo "TAR reports errors, this might or might not prevent the execution to run")
 ---> Running in cf2feb4b428e
tar: etc: Cannot unlink: Device or resource busy
tar: etc/resolv.conf: Cannot unlink: Device or resource busy
tar: Exiting with failure status due to previous errors
TAR reports errors, this might or might not prevent the execution to run
Removing intermediate container cf2feb4b428e

Thank you for the note on neurodocker generate

@kaczmarj
Copy link
Collaborator

kaczmarj commented Aug 30, 2019

@mathdugre i got a chance to look into this. i think the tar errors are benign -- they've come up on the reprozip github issues but don't seem to cause problems.

looks like the $PATH and $LD_LIBRARY_PATH variables are not correct in the 'reprozipped' image.

docker run --rm -it reprounzip_image_yzrjp25ry9:latest /busybox ash
/busybox --install
export PATH="/usr/lib/fsl/5.0:$PATH"
export LD_LIBRARY_PATH="/usr/lib/fsl/5.0:$LD_LIBRARY_PATH"
bet --help

i wrote the ndminify script to make it easier to have a usable container after minification. (when you minimize aggressively in the standard way, things we might take for granted like bash can be removed, and it often becomes very difficult to use a container interactively)

so here is what i did with ndminify. i would suggest using that to minify for now. just be extremely careful because if you try to minify mounted directories that contain your data, you risk losing that data. i put some checks in place to prevent this, but please read through the list of files that will be deleted before deleting.

i pushed some updates so please re-install with

pip install --no-cache-dir docker  https://github.com/kaczmarj/neurodocker/tarball/add/minify-gently
ndminify -c bids-example -d /usr/bin /usr/lib --commands "$cmd1" "$cmd2"

# This step does not preserve environment variables, so they have to be reset.
docker export bids-example | docker import - bids-example-minified

docker run --rm -it bids-example-minified bash
export PATH=/usr/lib/fsl/5.0:$PATH
export LD_LIBRARY_PATH=/usr/lib/fsl/5.0:$LD_LIBRARY_PATH
bet -h

you can write a Dockerfile to set these things up for you. the minification would be an intermediate process.

FROM bids-example-minified
ENV PATH=/usr/lib/fsl/5.0:$PATH \
    LD_LIBRARY_PATH=/usr/lib/fsl/5.0:$LD_LIBRARY_PATH
ENTRYPOINT ["python3", "/run.py"]

this minified image is 510 MB, whereas the original bids/example image is 1.13 GB.

@mathdugre
Copy link
Author

mathdugre commented Sep 23, 2019

Hi @kaczmarj, sorry for the long delay. Unfortunately, this doesn't seem to work. While the bet -h command executes correctly, commands that use the tool won't execute; e.g.
python3 /run.py /data /outputs participant

This is the error message:

bet /data/IPCAS_4/sub-0026190/ses-1/anat/sub-0026190_ses-1_run-1_T1w.nii.gz /outputs/sub-0026190_ses-1_run-1_brain.nii.gz
/usr/lib/fsl/5.0/bet: 1: /usr/lib/fsl/5.0/bet: /bin/remove_ext: not found
/usr/lib/fsl/5.0/bet: 1: /usr/lib/fsl/5.0/bet: /bin/remove_ext: not found
/usr/lib/fsl/5.0/bet: 1: /usr/lib/fsl/5.0/bet: /bin/imtest: not found
/usr/lib/fsl/5.0/bet: 154: [: =: unexpected operator
/usr/lib/fsl/5.0/bet: 236: /usr/lib/fsl/5.0/bet: /bin/bet2: not found

It looks like the symlinks are broken after using
docker export bids-example | docker import - bids-example-minified
I am currently working on a bash script to fix this issue.

@mathdugre
Copy link
Author

Hi @kaczmarj, I figured out my issue. When I copied the environment variable in the minified container I was not exporting them. Now everything works, thank you :)

@kaczmarj
Copy link
Collaborator

kaczmarj commented Oct 4, 2019

excellent! thanks for the followup, and sorry the container minification is tricky. it will get better over time... do you mind posting the commands you used for the minification? that will help future readers.

@mathdugre
Copy link
Author

To obtain the minified container image I followed the below steps:
*Note that I used the bids app example with the corr/IPCAS_4 (BIDS) dataset.

# Install the updated version of ndminify
pip install --no-cache-dir docker  https://github.com/kaczmarj/neurodocker/tarball/add/minify-gently
# Initialize environment variable
export DOCKER_FLAG='-v /path/to/data:/data -v /path/to/outputs:/outputs'
export cmd1='python3 /run.py /data/IPCAS_4 /outputs participant'
export cmd2='python3 /run.py /data/IPCAS_4 /outputs group'
docker run  --rm -itd --entrypoint="bash" --name bids-example $DOCKER_FLAG bids/example
ndminify -c bids-example -d /usr/bin /usr/lib --commands "$cmd1" "$cmd2"

# This step does not preserve environment variables, so they have to be reset.
docker export bids-example | docker import - bids-example-minified

Create a Docker file as follow:

 FROM bids-example-minified

 ENV POSSUMDIR=/usr/share/fsl/5.0 \
     HOSTNAME=9af3e0876db7 \
     LD_LIBRARY_PATH=/usr/lib/fsl/5.0: \
     HOME=/root \
     FSLDIR=/usr/share/fsl/5.0 \
     FSLMULTIFILEQUIT=TRUE \
     FSLTCLSH=/usr/bin/tclsh \
     TERM=xterm \
     PATH=/usr/lib/fsl/5.0:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
     FSLOUTPUTTYPE=NIFTI_GZ \
     FSLWISH=/usr/bin/wish \
     PWD=/ \
     PYTHONPATH=         

ENTRYPOINT ["/run.py"] 

Execute the minimized container:

docker run --rm -it $DOCKER_FLAG bids-example-minified /data/IPCAS_4 /outputs participant
docker run --rm -it $DOCKER_FLAG bids-example-minified /data/IPCAS_4 /outputs group

@kaczmarj
Copy link
Collaborator

thank you @mathdugre - i will close this issue now. please re-open or open a new issue if you experience problems in the future or for any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants