Skip to content

Instantly share code, notes, and snippets.

@toniher
Last active February 2, 2020 07:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toniher/7ed9411db1e2c8369a4a7245c748766c to your computer and use it in GitHub Desktop.
Save toniher/7ed9411db1e2c8369a4a7245c748766c to your computer and use it in GitHub Desktop.
Bash script wrapper for generating a singularity image from a local Docker image
#!/bin/bash
# Based on https://github.com/sylabs/singularity/issues/1537
# Usage: bash docker2singularity.sh mydockerimg mysingularity.simg
set -ueo pipefail
IMG=$1
FILEOUT=$2
PORT=${3:-5000}
if [ -f $FILEOUT ]; then
echo "File $FILEOUT exists!"
exit 1
fi
docker run -d -p $PORT:5000 --restart=always --name "registry-$IMG" registry:2
# Push local docker container to it
docker tag $IMG localhost:$PORT/$IMG
docker push localhost:$PORT/$IMG
# Build singularity container
SINGULARITY_NOHTTPS=1 singularity build $FILEOUT docker://localhost:$PORT/$IMG
docker rm -f "registry-$IMG"
docker rmi localhost:$PORT/$IMG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment