docker2singularity

docker2singularity

Docker容器到Singularity镜像的高效转换工具

docker2singularity是一个将Docker镜像转换为Singularity镜像的开源工具。它支持squashfs、sandbox和ext3等多种输出格式,可自定义挂载点和镜像名称。该工具简化了Docker到Singularity的迁移过程,适用于Linux、Mac和Windows系统。docker2singularity主要面向HPC集群用户,使研究人员能在支持Singularity的环境中运行Docker容器。

Docker2Singularity容器转换SingularityDockerHPCGithub开源项目

docker2singularity

<img src="img/logo.png" alt="https://www.sylabs.io/guides/latest/user-guide" data-canonical-src="https://www.sylabs.io/guides/latest/user-guide" width="200" height="200">

CircleCI

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.

Usage

$ 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

Options

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)

Legacy

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.

Requirements

  • Docker (native Linux or Docker for Mac or Docker for Windows) - to create the Singularity image.
  • Singularity >= 2.1 - to run the Singularity image (versions 2.0 and older are not supported!). Note that if running a 2.4 image using earlier versions, not all (later developed) features may be available.

Examples

Build a Squashfs Image

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

Custom Naming

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

Inspect Your Image

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" } }

Build a Sandbox Image

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

Build a Legacy (ext3) Image

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

Contributed Examples

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!

  • docker2singularity-demo: an example of using docker2singularity on MacOS and using Vagrant to test the output Singularity image, complete with notes and a nice Makefile.

Tips for making Docker images compatible with Singularity

  • Define all environmental variables using the ENV instruction set. Do not rely on .bashrc, .profile, etc.
  • Define an ENTRYPOINT instruction set pointing to the command line interface to your pipeline
  • Do not define CMD - rely only on ENTRYPOINT
  • You can interactively test the software inside the container by overriding the ENTRYPOINT docker run -i -t --entrypoint /bin/bash bids/example
  • Do not rely on being able to write anywhere other than the home folder and /scratch. Make sure your container runs with the --read-only --tmpfs /run --tmpfs /tmp parameters (this emulates the read-only behavior of Singularity)
  • Don’t rely on having elevated user permissions
  • Don’t use the USER instruction set

FAQ

Here are some frequently asked questions if you run into trouble!

"client is newer than server" error

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.

My cluster/HPC requires Singularity images to include specific mount points

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

Development

1. Build the container

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} .

2. Test the container

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!

3. Documentation

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.

Acknowledgements

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

编辑推荐精选

博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
商汤小浣熊

商汤小浣熊

最强AI数据分析助手

小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能以快速、准确的响应满足您的需求,让您的生活更加智能便捷。

imini AI

imini AI

像人一样思考的AI智能体

imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。

下拉加载更多