As @tsnowlan said in their answer, typically the workflow is from Docker to Singularity. But there is a way to make a Docker image from an existing Singularity image. This would not make use of Docker's layer caching features.
The general idea is to:
- Dump the Singularity image filesystem as a squashfs file.
- Extract the squashfs file into a directory.
- Create a Dockerfile that inherits from scratch, copies over the Singularity image's filesystem, and sets environment variables and other things.
- Build the Docker image.
Here it is in bash, demonstrated on alpine:latest
:
singularity pull docker://alpine:latest
# Find out which SIF ID to use (look for Squashfs)
singularity sif list alpine_latest.sif
# Get the environment variables defined in the Singularity image.
singularity sif dump 2 alpine_latest.sif
singularity sif dump 3 alpine_latest.sif > data.squash
unsquashfs -dest data data.squash
# See the Dockerfile definition below
docker build --tag alpine:latest .
Contents of Dockerfile:
FROM scratch
COPY data /
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CMD ["/bin/ash"]
For more information on Singularity and Docker, I recommend looking at Singularity's documentation on the topic.