{"id":3,"date":"2022-01-04T17:32:43","date_gmt":"2022-01-04T17:32:43","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/?p=3"},"modified":"2022-01-04T17:32:43","modified_gmt":"2022-01-04T17:32:43","slug":"docker-and-singularity-containers-which-one-is-better","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/2022\/01\/04\/docker-and-singularity-containers-which-one-is-better\/","title":{"rendered":"Docker and Singularity containers: which one is better?"},"content":{"rendered":"\n<p><strong>1.0 Introduction<\/strong><\/p>\n\n\n\n<p><strong><\/strong>Building a web application using containers is one of the new technologies that I and my Capstone team need to learn and master. I researched and self-learned to build Docker images and run docker stack services to create a microservice web application. However, there is a need for our project to build an internal web application which is run on the HPC system. As a result, Singularity containers become more preferable than Docker\u2019s. However, the process of converting from Docker\u2019s multi-containers to a single Singularity container seems to be challenging. In this blog, I differentiate the differences between Singularity and Docker. Hopefully, this will help new learners to gain some insights when choosing the right container technologies for their applications.&nbsp;<\/p>\n\n\n\n<p><strong>2.0\u00a0 Docker containers:<\/strong><\/p>\n\n\n\n<p><strong>2.1 Limitations:\u00a0<\/strong><\/p>\n\n\n\n<p>To maintain the Docker engine, Docker daemon needs to be run in the background; Docker daemon needs root privileges, which could potentially be a security concern. Only trusted users should be allowed to control your Docker daemon [1]. Otherwise, without limiting access rights, containers can alter the host filesystem as Docker host and guest containers share a directory. However, some extra steps can be done to reduce these security risks. For example, enabling SELinux and not allowing users to mount directories outside Docker context. Also, binding options should only apply to trusted user-defined paths and the filesystem maintains proper user\u2019s ownership rights [2].&nbsp;<\/p>\n\n\n\n<p><strong>2.2 Strengths:<\/strong><\/p>\n\n\n\n<p>Docker is suitable for DevOps engineering; Docker provides cloud-native micro-services to users [3]. With Docker swarm, multiple Docker containers can be run and connected on multiple hosts. With Docker compose, multiple Docker containers can be configured and started on the same host. Docker Hub provides a great number of pre-built Docker images, which is convenient to meet the needs of many applications.&nbsp;<\/p>\n\n\n\n<p><strong>3.0 Singularity containers:<\/strong><\/p>\n\n\n\n<p><strong>3.1 Limitations:<\/strong><\/p>\n\n\n\n<p>Singularity containers are not as popular as Docker containers are. For Windows users, for example, users can set up a Docker desktop but cannot install a Singularity desktop. To run Singularity locally, Windows\u2019 users have to install many dependencies including Git Bash, Vagrant, and Virtual Box [5]. In addition, when encountering problems with container technologies, Docker containers seem to have more support from a large number of users. Singularity has smaller numbers of users; thus, new learners might find it is challenging when building applications with Singularity.&nbsp;<\/p>\n\n\n\n<p><strong>3.2 Strengths:<\/strong><\/p>\n\n\n\n<p>Singularity containers are preferred when running applications in HPC systems. Singularity containers can be run without sudo. Unprivileged users can also use &#8211;remote or &#8211;fakeroot features to build Singularity containers. In addition, Singularity can convert Docker containers to Singularity, or can run containers directly from Docker Hub, or can pull images from Singularity Hub.&nbsp;<\/p>\n\n\n\n<p><strong>4.0 Differences between Singularity definition file and Dockerfile:<\/strong><\/p>\n\n\n\n<p>Understanding the basic differences between the Singularity definition file and Dockerfile could help users to quickly build Singularity definitions files when it is necessary.&nbsp;<\/p>\n\n\n\n<p>Singularity definition files have header and section. Header has the keyword \u201cBootstrap\u201d. Depending on bootstrap agents, other keywords need to be added. For example: \u201cFrom\u201d, \u201cOSVersion\u201d, \u201cMirrorURL\u201d, \u201cinclude\u201d, \u201cFingerprints\u201d. Sections start with % followed by the names of the sections. Common sections are %setup, %files, %environment, %post, %runscripts, %startscripts, %test, %label. %help, %app*.&nbsp;<\/p>\n\n\n\n<p>In contrast to Singularity, dockerfile can only use Docker Hub to bootstrap. Also, Dockerfile does not support %setup, %startscript, % help, and&nbsp; %app*. Instead of %files, %environment, %post, %runscript, %test, and %label, dockerfile uses different section names including COPY, ENV, RUN, CMD, HEALTHCHECK, and LABEl respectively [4].&nbsp;<\/p>\n\n\n\n<p><strong>5.0\u00a0 Conclusion:<\/strong><\/p>\n\n\n\n<p>Understanding pros and cons of Docker and Singularity containers could help developers select suitable container technology for their applications. From my own experience, it is faster to build and deploy Docker containers; the main concern is the security risks that prevent usage of Docker containers on HPC systems.&nbsp;<\/p>\n\n\n\n<p><strong>Reference<\/strong><\/p>\n\n\n\n<p>[1] Docker docs. (Docker Security.&nbsp; [Online]. Available: <a href=\"https:\/\/docs.docker.com\/engine\/security\/\">https:\/\/docs.docker.com\/engine\/security\/<\/a>. Accessed Jan 3rd, 2022.<\/p>\n\n\n\n<p>[2] Nishanth Dandapanthula. (2018). [Online]. Available: <a href=\"https:\/\/www.nextplatform.com\/2018\/03\/19\/singularity-containers-for-hpc-deep-learning\/\">https:\/\/www.nextplatform.com\/2018\/03\/19\/singularity-containers-for-hpc-deep-learning\/<\/a>. Accessed Jan 3rd, 2022.&nbsp;<\/p>\n\n\n\n<p>[3] RRZE. (2020). Introduction to software containers with Singularity. [Online]. Available: <a href=\"https:\/\/hpc.fau.de\/files\/2020\/05\/2020-05-12-singularity-containers.pdf\">https:\/\/hpc.fau.de\/files\/2020\/05\/2020-05-12-singularity-containers.pdf<\/a>. Accessed Jan 3rd, 2022<\/p>\n\n\n\n<p>[4] Singularity container. Support for Docker and OCI. [Online]. Available: <a href=\"https:\/\/sylabs.io\/guides\/3.5\/user-guide\/singularity_and_docker.html#sec-deffile-vs-dockerfile\">https:\/\/sylabs.io\/guides\/3.5\/user-guide\/singularity_and_docker.html#sec-deffile-vs-dockerfile<\/a>. Accessed Jan 3rd, 2022.&nbsp;<\/p>\n\n\n\n<p>[5] Singularity docs. Installation. [Online]. Available: <a href=\"https:\/\/sylabs.io\/guides\/3.0\/user-guide\/installation.html\">https:\/\/sylabs.io\/guides\/3.0\/user-guide\/installation.html<\/a>. Accessed Jan 3rd, 2022.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.0 Introduction Building a web application using containers is one of the new technologies that I and my Capstone team need to learn and master. I researched and self-learned to build Docker images and run docker stack services to create a microservice web application. However, there is a need for our project to build an&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/learningbydoing\/2022\/01\/04\/docker-and-singularity-containers-which-one-is-better\/\">Continue reading <span class=\"screen-reader-text\">Docker and Singularity containers: which one is better?<\/span><\/a><\/p>\n","protected":false},"author":11550,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/posts\/3","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/users\/11550"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/comments?post=3"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/posts\/3\/revisions"}],"predecessor-version":[{"id":4,"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/posts\/3\/revisions\/4"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/media?parent=3"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/categories?post=3"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/learningbydoing\/wp-json\/wp\/v2\/tags?post=3"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}