Commit Docker Image - mbarnig/RadioLogic GitHub Wiki

It's safe now to create a new image from all the stuff added to the original debian image in the currently stopped debian-container. We call our new image dev-snapshot by using the following command

docker commit debian-container dev-snapshot

It takes some time to copy all the files in the layers. Finally Docker returns a sha256 hash as a confirmation.

dev-snapshot

The command docker images displays all current images saved in the Docker system on the diskstation. The dev-snapshot image has a size of 1.87 GB, which is very high compared to the 114 MB of the original debian image or the 202 MB of the image sjodogne/orthanc-plugins.

If we consider that the Orthanc executable has only a size of 14,4 MByte, it's sort of overkill to run a program of 1.87 GB to execute such a small process.

Why is the resulting image so large? The reason is that it contains all the libraries, files and source-code to compile the target Orthanc which are no longer needed to run the RadioLogicArchive Docker container.

We go back to our stopped debian-container and try to delete the whole Orthanc directory with the source code and all the libraries and build files in the OrthancBuild directory. As we copied already the libServeFolders plugin, we only need to keep the Orthanc executable. To clean the image, we restart the debian container, move the executable to the /orthanc folder and delete the rest. Here are the related commands to enter, line by line:

docker restart debian-container   
docker attach debian-container     
cd /orthanc         
rm -r Orthan   
cd OrthancBuild    
cp Orthanc /orthanc/Orthanc   
cd ..    
rm -r OrthancBuild    
Ctrl d  

We commit the cleaned container to a new image with the command

docker commit debian-container clean-snapshot

clean-snapshot

By inspecting the size of the new image we see that it has been reduced to 1.26 GBbyte, which is still excessive.

We will now try to remove all the development tools installed in lesson 5 with their dependencies. In a last step we will delete the cache and clean the remaining space.

The opposite commands to apt-get install are apt-get remove and apt-get purge. The last command removes also the related configuration files, which is not the case for remove. You probably guess that our next command to run, in a single line, is

apt-get purge -y \
build-essential \
cmake \
mercurial \
git \
wget \
unzip \
uuid-dev \
libcurl4-openssl-dev \
liblua5.1-0-dev \
libgtest-dev \
libpng-dev \
libjpeg-dev \
libsqlite3-dev \
libssl-dev \
zlib1g-dev \
libdcmtk2-dev \
libboost-all-dev \
libwrap0-dev \
libjsoncpp-dev \
libpugixml-dev \
nano \
bzip2

followed by the commands, line by line

apt-get autoremove  
apt-get clean  
rm -rf /var/lib/apt/lists/*  
Ctrl d 

With autoremove we delete all the additional dependencies that have been automatically installed by the libraries listed in the purge command.

purge-autoremove

Now we have done everything that is possible to delete waste stuff in the container. We are so keen to commit the container to a final Docker image named radiologicarchive with the command

docker commit debian-container radiologicarchive

radiologicarchive-image

Wow! The image size is now 142 MByte. Even smaller than the official Orthanc images! That's great.

To finish this lesson, let's inspect the layers of the radiologicarchive image with the command

docker history radiologicarchive

image-history

There are only 3 layers. A comparison with the original debian image shows that all the RadioLogicArchive specific files are saved in the top layer. The two lower layers are those from the source image.

If we look at the history of the offical Orthanc image jodogne/orthanc-plugins, we see multiple layers. This is typical for images created with a DockerFile.

jodogne-orthanc-image

In the next lesson we will see if a container created with our radiologicarchive image is working as expected. If you are curious, continue with Run Docker Container.