This script exports a Docker image as a Singularity .sif
file. This can be useful for porting Dockerized code to run on shared user systems like clusters, which sometimes run Singularity rather than Docker.
- Install Docker (tested on Mac OS
10.14.6
with Docker20.10.6
)
-
Build or pull the Docker image you wish to export to a Singularity
.sif
filedocker pull ubuntu:latest
-
Run
docker2singularity.sh
to export the image as a.sif
filecd docker2singularity ./docker2singularity.sh ubuntu
This should write a file called
ubuntu.sif
in the current working directory, e.g.,docker2singularity/ubuntu.sif
Optionally, you can specify where to save the output
.sif
file:./docker2singularity.sh ubuntu $HOME/ubuntu_singularity.sif
If it worked, you'll see output similiar to the following:
Exporting docker image ubuntu --> /Users/matt/ubuntu_singularity.sif Image Format: squashfs Docker Image: ubuntu Container Name: ubuntu_singularity.sif Inspected Size: 73 MB (1/10) Creating a build sandbox... (2/10) Exporting filesystem... (3/10) Creating labels... (4/10) Adding run script... (5/10) Setting ENV variables... (6/10) Adding mount points... (7/10) Fixing permissions... (8/10) Stopping and removing the container... (9/10) Building squashfs container... INFO: Starting build... INFO: Creating SIF file... INFO: Build complete: /tmp/ubuntu_singularity.sif (10/10) Moving the image to the output folder... 27,717,632 100% 80.25MB/s 0:00:00 (xfr#1, to-chk=0/1) Final Size: 27MB Exported Docker image ubuntu --> /Users/matt/ubuntu_singularity.sif
Run
./docker2singularity -h
to print the help screen, including usage.
In order to export a Docker image to .sif
file, one of the following must be true:
-
The Docker image is available locally (i.e., it has already been built using
docker build
or pulled usingdocker pull
) -
A file named
Dockerfile
exists in the current working directory.
If a Dockerfile
is found, you are given the option to build the docker image and then export it to .sif
.
If neither of these conditions is met, an error message is printed and the program exits without doing anything.