Maintaining Open Source Singularity Since 2017
Hybrid Docker/Singularity Workflow
By Adam Hughes
Overview
The hybrid workflow of Singularity with Docker containers combines the strengths of both technologies to provide a flexible and efficient containerization solution. With Singularity’s ability to natively run Docker containers, users can leverage the vast Docker ecosystem and easily incorporate Docker images into their Singularity workflows. This hybrid approach allows users to benefit from Singularity’s security, reproducibility, and compatibility with HPC systems while taking advantage of Docker’s extensive collection of pre-existing containers and tools. It provides a seamless bridge between the two container technologies, enabling users to run Docker containers within Singularity with minimal effort and enabling efficient collaboration across diverse computing environments. As work progresses towards SingularityCE 4.0 and beyond, let’s take a look at what is possible today with Singularity Enterprise and SingularityCE/PRO.- The following code examples require SingularityCE version 3.11.4 or later. If you are a customer using SingularityPRO, please update to either SingularityPRO 3.9-11, or SingularityPRO 3.11-3 or later.
- The examples also works with Singularity Enterprise version 2.3 or later, as well as the Sylabs-hosted version called Singularity Container Services at https://cloud.sylabs.io.
- Singularity Enterprise has three functions: Remote Builder, Library and KeyStore.
- The terms Singularity Container Service and SCS are synonyms and used indistinctly.
Closing the gap
Singularity Enterprise and Singularity Container Services now include functionality to store OCI images and artifacts, in addition to SIF images. This means that we can build an image using a Dockerfile, upload it to the Library, and run it using SingularityCE/PRO.FROM golang:1.20-alpine
RUN apk add git
RUN git clone https://github.com/golang/example
RUN cd example/hello && go build && mv hello /
CMD ["/hello"]
$ docker build -t example .
[+] Building 3.7s (8/8) FINISHED
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 252B 0.0s
=> [internal] load metadata for docker.io/library/golang:1.20.2 0.0s
=> [1/4] FROM docker.io/library/golang:1.20.2-alpine 0.0s
=> CACHED [2/4] RUN apk add git 0.0s
=> CACHED [3/4] RUN git clone https://github.com/golang/example 0.0s
=> [4/4] RUN cd example/hello && go build && mv hello / 3.5s
=> exporting to image 0.2s
=> => exporting layers 0.1s
=> => writing image sha256:f0c5b17de57822...5dbff 0.0s
=> => naming to docker.io/library/example
$ docker run example
Hello, Go examples!
$ singularity remote add local cloud.sylabs.io
INFO: Remote "local" added.
Generate an access token at https://registry.sylabs.io/auth/tokens, and paste it here.
Token entered will be hidden for security.
Access Token:
$ singularity remote use local
$ singularity remote get-login-password | \
docker login -u USERNAME --password-stdin registry.sylabs.io
WARNING! Your password will be stored unencrypted in /home/almalinux/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ docker tag example registry.sylabs.io/USERNAME/example:v1.0
$ docker push registry.sylabs.io/USERNAME/example:v1.0
The push refers to repository [registry.sylabs.io/USERNAME/example]
dfc1c98e1bbf: Pushed
775e259e565c: Pushing [==============================> ] 148.1MB/246.5MB
4984fbd72df1: Pushed
bb01bd7e32b5: Pushed
$ singularity remote get-login-password | \
singularity remote login --username USERNAME \
--password-stdin docker://registry.sylabs.io
INFO: Token stored in /home/almalinux/.singularity/remote.yaml
$ singularity run \
docker://registry.sylabs.io/USERNAME/example/example:v1.0
INFO: Converting OCI blobs to SIF format
INFO: Starting build...
Getting image source signatures
Copying blob 100b0fdef129 done
Copying blob d694b5ae8c79 skipped: already exists
Copying blob f56be85fc22e skipped: already exists
Copying blob 9f32a84ed3da skipped: already exists
Copying blob a9354d4031ea done
Copying blob 85791d961cd3 skipped: already exists
Copying blob c74873be681f done
Copying config 61ce683a0a done
Writing manifest to image destination
Storing signatures
2023/05/13 19:41:59 info unpack layer: sha256:f56be822e...d29d7f64b87a09
2023/05/13 19:41:59 info unpack layer: sha256:85791d961...cd35e9127a7907
2023/05/13 19:41:59 info unpack layer: sha256:d694b5ae8...c79da87345cbc6
2023/05/13 19:42:01 info unpack layer: sha256:9f32a84ed...3adb91a7ddf893
2023/05/13 19:42:01 info unpack layer: sha256:a938340aa...fa14813eeed798
2023/05/13 19:42:01 info unpack layer: sha256:100b0fdef...129a7d1fa7a44e
2023/05/13 19:42:01 info unpack layer: sha256:c74873be6...81fecc83acddcc7
INFO: Creating SIF file...
Hello, Go examples!
Bootstrap: docker
From: registry.sylabs.io/USERNAME/example/example:v1.0
%post
# Any other instructions goes here
$ singularity build --fakeroot example.sif example.def
INFO: Starting build...
INFO: Setting maximum build duration to 20m0s
INFO: Remote "registry.sylabs.io" added.
INFO: Access Token Verified!
INFO: Token stored in /root/.singularity/remote.yaml
INFO: Remote "registry.sylabs.io" now in use.
INFO: Starting build...
Getting image source signatures
Copying blob sha256:361237ddf3...18f0b3435
Copying config sha256:d710383bdc8e0a...394af54773632
...
Conclusion
Singularity Enterprise 2.3+ and Singularity Container Service allows more flexibility than ever to work with the increasing number of tools in the OCI ecosystem. Whether it’s building and testing container images with Docker, Kubernetes, SingularityPRO, or any other tools leveraging the OCI standards, Singularity Enterprise and Singularity Container Service provides a single place to store and manage your container images and OCI artifacts.Join Our Mailing List
Recent Posts
Related Posts
Laying the Groundwork for 2025: Sylabs’ Vision for Secure Multi-Cloud Solutions
With a legacy rooted in innovation through the work we’ve done with the Singularity platform, Sylabs has consistently worked to provide secure container technology to empower researchers, enterprises, and innovators worldwide. These efforts have paid dividends as we...
Creating New Levels of Security with Containers and Confidential Computing
Data breaches are becoming increasingly common. It's more important than ever to find robust solutions that protect sensitive information. Recent high-profile data breaches underscore the necessity for fresh approaches to data protection. Breaches like these are...
OCI-SIF Container Images: Unraveling Their Features and Benefits
Among the container industry, OCI (Open Container Initiative) and SIF (Singularity Image Format) stand out as two prominent formats, each offering unique features and benefits. Understanding their distinct characteristics is crucial for HPC developers seeking optimal...
