How to build a workable docker image ¶
By: xinjie on Aug. 1, 2022, 9:16 a.m.
Details to build a docker image for your algorithm
Please name your docker image as your teamname, and the tag is latest, then save your docker image as teamname.tar.gz, and send us a link to download the tar file. Note that, the docker image name requires lowercase letters. You can use the following command to generate the docker tar file.
docker save teamname:latest -o teamname.tar.gz
Don't forget the -o option , otherwise, the docker image will not be loaded properly if the save and load are executed on a different OS because of the difference in the behavior of STDOUT between Windows and Unix. (https://stackoverflow.com/questions/40622162/docker-load-and-save-archive-tar-invalid-tar-header)
When we receive your docker tar file, we will run your program with commands as follows
docker load < teamname.tar.gz docker run --gpus "device=0" -name teamname -v /home/amax/Desktop/input:/input -v /home/amax/Desktop/predict:/predict teamname:latest
Folder /home/amax/Desktop/input (a folder contains all CT files for testing) will be synchronized with /input in your docker container, and folder /home/amax/Desktop/predict (an empty folder used to save segmentation file) will be synchronized with /predict in your docker container. ├── /home/amax/Desktop/input │ ├── PA0007.nii.gz │ ├── PA0008.nii.gz │ ├── PA0009.nii.gz . . .
├── /predict │ ├── PA0007.nii.gz │ ├── PA0008.nii.gz │ ├── PA0009.nii.gz . . .
We highly recommend that you test the docker with the training data before sending it to us since downloading and uploading the zip file is time consuming for both the participants and the organizers.
Your program in your docker container should do the following things: · obtain each CT file(.nii.gz) in folder /input · apply your segmentation algorithm to segment the target · save the segmentation mask to /predict. Note that, the filename of the segmentation mask file should be the same as the CT file, the segmentation mask is a 3D zero-one array(0 stands for background, 1 stands for target), and the meta information of the segmentation mask file should be consistent with that of original CT file
Use dockerfile to build your docker image
FROM → The FROM instruction initializes a new build stage and sets the base image for subsequent instructions WORKDIR → The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it COPY → The COPY instruction copies new files or directories from and adds them to the filesystem of the container at the path RUN → The RUN instruction will execute any commands in a new layer on top of the current image and commit the results CMD → The main purpose of a CMD is to provide defaults for an executing container
Note that COPY and RUN are executed when you build your docker image using ‘docker build’, and CMD is executed when you run your docker container using ‘docker run’.
If you don't know how to build a docker image for your program, you can refer to the video https://youtu.be/wkHUtOCEHro
and the example https://github.com/PerceptionComputingLab/PARSE2022/tree/main/build-docker-image-example.