Docker容器到Singularity镜像的高效转换工具
docker2singularity是一个将Docker镜像转换为Singularity镜像的开源工具。它支持squashfs、sandbox和ext3等多种输出格式,可自定义挂载点和镜像名称。该工具简化了Docker到Singularity的迁移过程,适用于Linux、Mac和Windows系统。docker2singularity主要面向HPC集群用户,使研究人员能在支持Singularity的环境中运行Docker容器。
docker2singularity
Are you developing Docker images and you would like to run them on an HPC cluster
supporting Singularity?
Are you working on Mac or Windows with no easy access to a Linux machine? If the pull,
build, and general commands to work with docker images provided by Singularity
natively do not fit your needs, docker2singularity
is an alternative way to generate Singularity images.
The containers are available to you on quay.io,
and older versions also available for you on Docker Hub.
$ docker run quay.io/singularity/docker2singularity USAGE: docker2singularity [-m "/mount_point1 /mount_point2"] [options] docker_image_name OPTIONS: Image Format --folder -f build development sandbox (folder) --option -o add a custom option to build (-o --fakeroot or -option 'section post' ) --writable -w non-production writable image (ext3) Default is squashfs (recommended) (deprecated) --name -n provide basename for the container (default based on URI) --mount -m provide list of custom mount points (in quotes!) --help -h show this help and exit
Image Format
squashfs
(no arguments specified) gives you a squashfs (*.simg
) image. This is a compressed, reliable, and read only format that is recommended for production images. Squashfs support was added to Singularity proper in January of 2017 and thus available as early as the 2.2.1 release.sandbox
(-f
) builds your image into a sandbox folder. This is ideal for development, as it will produce a working image in a folder on your system.ext3
(-w
) builds an older format (ext3) image (*.img
). This format is not recommended for production images as we have observed degradation of the images over time, and they tend to be upwards of 1.5x to 2x the size of squashfs.Note that you are able to convert easily from a folder or ext3 image using Singularity 2.4. If your choice is to develop, making changes, and then finalize, this approach is not recommended - your changes are not recorded and thus the image not reproducible.
Mount Points
-m
specify one or more mount points to create in the image.Options
If you look at singularity build --help
there are a variety of options available.
You can specify some custom option to the command using the --option
flag. Make sure
that each option that you specify is captured as a single string. E.g.,:
--option --fakeroot --option '--section post'
Image Name
The last argument (without a letter) is the name of the docker image, as you would specify to run with Docker (e.g., docker run ubuntu:latest
)
If you want a legacy version, see the repository branches and tag history on the registry.
Containers were previous built on Docker Hub and
now are provided on quay.io. A tag with prefix v
corresponds to a release of the Singularity software, while the others are in reference to releases of Docker. Previously used scripts, including environment and action files, are provided in this repository for reference.
Squashfs is the recommended image type, it is compressed and less prone to degradation over time. You don't need to specify anything special to create it:
This is a path on my host, the image will be written here
$ mkdir -p /tmp/test
And here is the command to run. Notice that I am mounting the path /tmp/test
that I created above to /output
in the container, where the container image will be written (and seen on my host).
$ docker run -v /var/run/docker.sock:/var/run/docker.sock \ -v /tmp/test:/output \ --privileged -t --rm \ quay.io/singularity/docker2singularity \ ubuntu:14.04 Image Format: squashfs Inspected Size: 188 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... Building image from sandbox: /tmp/ubuntu_14.04-2017-09-13-3e51deeadc7b.build Building Singularity image... Singularity container built: /tmp/ubuntu_14.04-2017-09-13-3e51deeadc7b.simg Cleaning up... (10/10) Moving the image to the output folder... 62,591,007 100% 340.92MB/s 0:00:00 (xfr#1, to-chk=0/1) Final Size: 60MB
We can now see the finished image!
$ ls /tmp/test ubuntu_14.04-2018-04-27-c7e04ea7fa32.simg
And use it!
$ singularity shell /tmp/test/ubuntu_14.04-2018-04-27-c7e04ea7fa32.simg Singularity: Invoking an interactive shell within container... Singularity ubuntu_14.04-2018-04-27-c7e04ea7fa32.simg:~/Documents/Dropbox/Code/singularity/docker2singularity>
Take a look again at the generation code above, and notice how the image went from 188MB to 60MB? This is one of the great things about the squashfs filesystem! This reduction is even more impressive when we are dealing with very large images (e.g., ~3600 down to ~1800). A few notes on the inputs shown above that you should edit:
/tmp/test
: the path you want to have the final image reside. If you are on windows this might look like D:\host\path\where\to\output\singularity\image
.
-ubuntu:14.04
: the docker image name you wish to convert (it will be pulled from Docker Hub if it does not exist on your host system).docker2singularity
uses the Docker daemon located on the host system. It will access the Docker image cache from the host system avoiding having to redownload images that are already present locally.
If you ever need to make changes, you can easily export the squashfs image into either a sandbox folder or ext3 (legacy) image, both of which have writable.
sudo singularity build --sandbox sandbox/ production.simg
sudo singularity build --writable ext3.img production.simg
Added for version 2.5.1, you can specify the name of your container with the -n/--name
argument, as follows:
docker run -v /var/run/docker.sock:/var/run/docker.sock \ -v /tmp/test:/output \ --privileged -t --rm \ quay.io/singularity/docker2singularity \ --name meatballs ubuntu:14.04 ... $ ls /tmp/test/ meatballs.simg
New with docker2singularity
2.4, the labels for the container are available with inspect
:
singularity inspect ubuntu_14.04-2017-09-13-3e51deeadc7b.simg { "org.label-schema.singularity.build": "squashfs", "org.label-schema.docker.version": "17.06.2-ce", "org.label-schema.schema-version": "1.0", "org.label-schema.singularity.build-type": "docker2singularity", "org.label-schema.docker.id": "sha256:dea1945146b96542e6e20642830c78df702d524a113605a906397db1db022703", "org.label-schema.build-date": "2017-10-28-17:19:18", "org.label-schema.singularity.version": "2.4-dist", "org.label-schema.docker.created": "2017-09-13" }
as is the runscript and environment
singularity inspect --json -e -r ubuntu_14.04-2017-09-13-3e51deeadc7b.simg { "data": { "attributes": { "environment": "# Custom environment shell code should follow\n\n", "runscript": "#!/bin/sh\n/bin/bash $@\n" }, "type": "container" } }
A sandbox image is a folder that is ideal for development. You can view it on your desktop, cd inside and browse, and it works like a Singularity image. To create a sandbox, specify the -f
flag:
docker run -v /var/run/docker.sock:/var/run/docker.sock \ -v /host/path/change/me:/output \ --privileged -t --rm \ quay.io/singularity/docker2singularity \ -f \ ubuntu:14.04
Importantly, you can use --writable
, and if needed, you can convert a sandbox folder into a production image:
sudo singularity build sandbox/ production.simg
You can build a legacy ext3 image (with --writable
) with the -w
flag. This is an older image format that is more prone to degradation over time, and (building) may not be supported for future versions of the software.
docker run -v /var/run/docker.sock:/var/run/docker.sock \ -v /host/path/change/me:/output \ --privileged -t --rm \ quay.io/singularity/docker2singularity \ -w \ ubuntu:14.04
You can also use --writable
and convert an ext3 image into a production image:
sudo singularity build ext3.img production.simg
The following are a list of brief examples and tutorials generated by the Singularity community for using docker2singularity. If you have an example of your own, please let us know!
ENV
instruction set. Do not rely on .bashrc
, .profile
, etc.ENTRYPOINT
instruction set pointing to the command line interface to your pipelineCMD
- rely only on ENTRYPOINT
ENTRYPOINT
docker run -i -t --entrypoint /bin/bash bids/example
/scratch
. Make sure your container runs with the --read-only --tmpfs /run --tmpfs /tmp
parameters (this emulates the read-only behavior of Singularity)Here are some frequently asked questions if you run into trouble!
If you are getting the following error:
docker: Error response from daemon: client is newer than server
You need to use the docker info
command to check your docker version and use it to grab the correct corresponding version of docker2singularity
. For example:
docker run \ -v /var/run/docker.sock:/var/run/docker.sock \ -v D:\host\path\where\to\output\singularity\image:/output \ --privileged -t --rm \ singularityware/docker2singularity:1.11 \ ubuntu:14.04
Currently only the 1.10, 1.11, 1.12, and 1.13 versions are supported. If you are using an older version of Docker you will need to upgrade.
If you are getting WARNING: Non existant bind point (directory) in container: '/shared_fs'
or a similar error when running your Singularity image that means that your Singularity images require custom mount points. To make the error go away you can specify the mount points required by your system when creating the Singularity image:
docker run \ -v /var/run/docker.sock:/var/run/docker.sock \ -v D:\host\path\where\to\output\singularity\image:/output \ --privileged -t --rm \ quay.io/singularity/docker2singularity \ -m "/shared_fs /custom_mountpoint2" \ ubuntu:14.04
You can build a development container as follows. First, update the VERSION to be correct.
VERSION=$(cat VERSION) image="quay.io/singularity/docker2singularity:${VERSION}" docker build -t ${image} .
We have a Circle CI builder that tests generation of the final image, and basic running to ensure the entrypoint is functioning. Since we cannot run the priviledged Docker daemon on Circle, a test.sh script is provided for local testing.
chmod u+x /bin/bash test.sh
If there are missing tests or you have added new features, please add the test here!
If you have added new features, please describe usage in the README.md here. Don't forget to read the CONTRIBUTING.md along with the code of conduct and add yourself to the authors file.
This work is heavily based on the docker2singularity
work done by vsoch
and gmkurtzer. The original record of the work can be read about
in this commit.
Thank you kindly to all the contributors, and please open an issue if you need
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号