GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • https://apptainer.org/docs/
  • Singularity
  • News
  • Docs
  • Admin Guide
  • User Guide
  • Archive
  • Contributed Content
  • Github Repo
  • Google Group
  • Singularity on Stack Overflow
  • Singularity Hub
  • Slack
  • Troubleshooting

This view

  • Original page
  • New address

GeezerVison is showing singularityware.github.io — Singularity Shell | Singularity

 
  • User Guide
  • Getting Started
    • Quick Start
    • Introduction
    • Installation
    • Build a Container
    • Build Environment
    • Container Recipes
    • Singularity Flow
    • Bind Paths and Mounts
    • Persistent Overlays
    • Running Services
    • Container Checks
    • Environment and Metadata
    • Reproducible SCI-F Apps
    • Singularity and Docker
    • Troubleshooting
  • Commands
    • Command Usage
    • build
    • exec
    • inspect
    • pull
    • run
    • shell
  • Image Command Group
    • image.export
    • image.expand
    • image.import
    • image.create
  • Instance Command Group
    • instance.start
    • instance.list
    • instance.stop
  • Deprecated
    • bootstrap

Singularity Shell

These docs are for Singularity Version 2.5.2. For older versions, see our archive

The shell Singularity sub-command will automatically spawn an interactive shell within a container. As of v2.3 the default shell that is spawned via the shell command is /bin/bash if it exists otherwise /bin/sh is called.

$ singularity shell
USAGE: singularity (options) shell [container image] (options)

Here we can see the default shell in action:

$ singularity shell centos7.img
Singularity: Invoking an interactive shell within container...

Singularity centos7.img:~> echo $SHELL
/bin/bash

Additionally any arguments passed to the Singularity command (after the container name) will be passed to the called shell within the container, and shell can be used across image types. Here is a quick example of shelling into a container assembled from Docker layers. We highly recommend that you look at the singularity shell help and our documentation on flags to better customize this command.

Change your shell

The shell sub-command allows you to set or change the default shell using the --shell argument. As of Singularity version 2.2, you can also use the environment variable SINGULARITY_SHELL which will use that as your shell entry point into the container.

Bash

The correct way to do it:

export SINGULARITY_SHELL="/bin/bash --norc"
singularity shell centos7.img Singularity: Invoking an interactive shell within container...
Singularity centos7.img:~/Desktop> echo $SHELL
/bin/bash --norc

Don’t do this, it can be confusing:

$ export SINGULARITY_SHELL=/bin/bash
$ singularity shell centos7.img 
Singularity: Invoking an interactive shell within container...

# What? We are still on my Desktop? Actually no, but the uri says we are!
vanessa@vanessa-ThinkPad-T460s:~/Desktop$ echo $SHELL
/bin/bash

Depending on your shell, you might also want the --noprofile flag. How can you learn more about a shell? Ask it for help, of course!

Shell Help

$ singularity shell centos7.img --help
Singularity: Invoking an interactive shell within container...

GNU bash, version 4.2.46(1)-release-(x86_64-redhat-linux-gnu)
Usage:	/bin/bash [GNU long option] [option] ...
	/bin/bash [GNU long option] [option] script-file ...
GNU long options:
	--debug
	--debugger
	--dump-po-strings
	--dump-strings
	--help
	--init-file
	--login
	--noediting
	--noprofile
	--norc
	--posix
	--protected
	--rcfile
	--rpm-requires
	--restricted
	--verbose
	--version
Shell options:
	-irsD or -c command or -O shopt_option		(invocation only)
	-abefhkmnptuvxBCHP or -o option
Type `/bin/bash -c "help set"' for more information about shell options.
Type `/bin/bash -c help' for more information about shell builtin commands.

And thus we should be able to do:

$ singularity shell centos7.img -c "echo hello world"
Singularity: Invoking an interactive shell within container...

hello world

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.