Edit this page on our live server and create a PR by running command !create-pr in the console panel

Running scripts in singularity

  • Difficulty level: intermediate
  • Time need to lean: 30 minutes or less
  • Key points:
    • Using container='library:xxx' etc will enable engine='singularity'
    • engine='singularity' is explicitly needed for docker images.

Before you run any script using singularity, please check if singularity is installed by checking the availability of command singularity. Also, it would be helpful for you to read the sigularity user's guide or some online tutorial to understand how singularity works before you try to use singularity in SoS.

Although running singularity images does not need root privilege, building singularity images often requires sudo access. SoS provides an option sudo=True to the singularity_build action (an equivalence to command singularity build) to execute the command in sudo mode, but it does not accept interactive input of password. So before running any singularity_build action with option sudo=True, please run sudo -i to enter sudo mode, or add your username as a sudo user without password (google "sudo without password" for instructions). The latter is not safe but can be very convenient for you to prepare singularity images on a personal linux workstation.

Running a script using singularity

Options container and engine

SoS executes scripts with a singularity container by calling command singularity exec with appropriate parameters. For example, if you specify a container with a library: schema, sos will first pull the image, save it as a local image, and use singularity exec to run it:

In [1]:
HINT: Pulling image library://alpine:latest to ~/.sos/singularity/library/alpine-latest.sif
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.9.2
PRETTY_NAME="Alpine Linux v3.9"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

The actual singularity exec command executed by SoS can be shown when you execute the script in dryrun mode (with -n option). In this mode, SoS would print the interpolated script (if option expand=True is set) and the docker command to execute it:

In [2]:
HINT: singularity exec  /home/bpeng1/.sos/singularity/library/alpine-latest.sif /bin/sh /home/bpeng1/sos/sos-docs/src/user_guide/tmpurin91a5/singularity_run_32484.sh
cat /etc/os-release

As you can see, the docker command looks similar to

singularity exec alpine-latest.sif /bin/sh /path/to/a/temp/script

Basically, SoS pulls the image and runs command singularity exec to execte the script with /bin/sh with the singularity image.

You can also use a docker image with singularity. However, because docker:// images are by default executed by docker, you will need to specify the use of singularity using parameter engine='singularity':

In [3]:
HINT: Pulling image docker://ubuntu to ~/.sos/singularity/library/ubuntu.sif
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

In summary, as listed here, you can invoke singularity with the following combinations of parameters container and engine:

container engine execute by example comment
filename.simg singularity container='ubuntu.simg'
shub://tag singularity container='shub://GodloveD/lolcow' Image will be pulled to a local image
library://tag singularity container='library://GodloveD/lolcow' Image will be pulled to a local image
name singularity singularity container='a_dir', engine='singularity' treat name as singularity image file or directory
docker://tag singularity singularity container='docker://godlovdc/lolcow', engine='singularity'
file://filename singularity container='file://ubuntu.simg'

Simply put, singularity will be used by default with container shub://, file://, and filename.simg, but you will have to specify engine='singularity' if you would like to use a docker image or a directory.

Running script with singularity image

Although singularity accepts docker://, shub://, and 'library://' container types, SoS always pull the image and build a local .sif file before executing it. If the container is used again, the local .sif file will be used directly.

For example, because an image has already been downloaded from the above example, SoS will not pull docker://ubuntu when using the container again

In [4]:
ls /
bin   dev	   etc	 lib	media  opt   root  sbin		srv  tmp  var
boot  environment  home  lib64	mnt    proc  run   singularity	sys  usr

You can use the name of the image directly (e.g. container='ubuntu.sif') if you know the image has been downloaded:

In [5]:
ls /
bin   dev	   etc	 lib	media  opt   root  sbin		srv  tmp  var
boot  environment  home  lib64	mnt    proc  run   singularity	sys  usr

Customize singularity image path

By default, downloaded singularity images are saved to the SoS Singularity Library located at ~/.sos/singularity/library. Environment variable SOS_SINGULARITY_LIBRARY can be used to set customized directory, e.g.,

export SOS_SINGULARITY_LIBRARY=/path/to/sif_folder

SoS will use *.sif files in $SOS_SINGULARITY_LIBRARY if they exist. As a result you can manually place existing image files to $SOS_SINGULARITY_LIBRARY to avoid pull images online attempts. This is useful when for example a workflow runs on a compute node without internet access.

Binding directories (option bind)

A very useful feature about singularity is that you can use the container almost as a local command with access to local file system,

In [6]:
wc -l ~/.bashrc
136 /home/bpeng1/.bashrc

However, singularity only binds current working directory, /tmp, and your home directory. Other directories would be from within the image, or appear to be missing even if they exist on the host file system. For example, the following command lists /usr/local inside the image:

In [7]:
ls /usr/local
bin  etc  games  include  lib  man  sbin  share  src

and /usr/local/var would appear to be missing

In [8]:
ls /usr/local/var
ls: cannot access '/usr/local/var': No such file or directory
ExecuteError: [0]: Executing script in Singularity returns an error (exitcode=2).
The script has been saved to /home/bpeng1/sos/sos-docs/src/user_guide/.sos/singularity_run_32376.sh. To reproduce the error please run:
``singularity exec  /home/bpeng1/.sos/singularity/library/ubuntu.sif /bin/bash -ev /home/bpeng1/sos/sos-docs/src/user_guide/.sos/singularity_run_32376.sh``

To allow singularity to see more directories, you can add one or more parameters to the bind parameter. For example, with bind='/usr/local', the singularity exec command lists directory /usr/local from the host filesystem:

In [9]:
ls /usr/local
bin  etc  games  go  include  lib  libexec  man  sbin  share  src  var

and we can see /usr/local/var actually exists

In [10]:
ls /usr/local/var
singularity

Parameter bind accepts host_dir:img_dir pairs to mount host_dir from host as img_dir seen by the image

In [11]:
ls /myvar
singularity

Other singularity exec options

You can use parameter entrypoint to change the environment in which the interpreter will be executed. An entrypoint is usually the name of a shell script that defines a number of environment variables and run the command given by the command line parameters in such a way that the current process is replaced by it,

#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

export MY_ENV=MY_VALUE

exec "$@"

but it can also be other commands such as micromamba run -n ENVIRONMENT.

For example, the following statement will execute interpreter Rscript

In [ ]:
INFO:    Running default:
INFO:    default is completed.
INFO:    Workflow default is executed successfully with 1 completed step.
Out[ ]:

It's equivalent to the following statement

In [ ]:

Building singularity images

If you need to pass other options to command singularity exec, you can specify them as additional keyword arguments for the run (or other) actions. For example,

In [ ]:

Note that you need to use format OPT=True to specify flag options such as --nv, and need to use underscore to specify options with - in their names.

Action singularity_build

Action singularity_build calls command singularity build with appropriate command line options. The SoS equivalence of the example in the singularity user's guide

singularity build lolcow.sif library://sylabsed/examples/lolcow

is the singularity_build action with options src and dest:

In [12]:
INFO:    Starting build...
INFO:    Creating SIF file...
INFO:    Build complete: lolcow.sif
Out[12]:
0

You can also use action singularity_build to build an image from a singularity definition file. Using an example from the user's guide:

In [13]:
INFO:    Starting build...
Getting image source signatures
Copying blob 3386e6af03b0 [--------------------------------------] 0b / 0b
Copying blob 49ac0bbe6c8e [--------------------------------------] 0b / 0b
Copying blob d1983a67e104 [--------------------------------------] 0b / 0b
Copying blob 1a0f3a523f04 [--------------------------------------] 0b / 0b
Copying blob 3386e6af03b0 skipped: already exists
Copying blob 49ac0bbe6c8e skipped: already exists
Copying blob d1983a67e104 skipped: already exists
Copying blob 1a0f3a523f04 skipped: already exists
Copying config ea9ba824b3 [====================================] 2.4KiB / 2.4KiB
Copying config ea9ba824b3 done
Writing manifest to image destination
Storing signatures
2019/12/30 11:38:13  info unpack layer: sha256:3386e6af03b043219225367632569465e5ecd47391d1f99a6d265e51bd463a83
2019/12/30 11:38:14  info unpack layer: sha256:49ac0bbe6c8eeb959337b336ceaa5c3bbbae81e316025f9b94ede453540f2377
2019/12/30 11:38:14  info unpack layer: sha256:d1983a67e104e801fceb1850a375a71fe6b62636ba7a8403d9644f308a6a43f9
2019/12/30 11:38:14  info unpack layer: sha256:1a0f3a523f04f61db942018321ae122f90d8e3303e243b005e8de9817daf7028
INFO:    Running post scriptlet
+ apt-get -y update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [1019 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]       
Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]     
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]    
Get:7 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [593 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6280 B]
Get:10 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1396 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [996 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.3 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B]
Get:18 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8807 B]
Fetched 16.2 MB in 3s (4260 kB/s)                          
Reading package lists... Done
+ apt-get -y install fortune cowsay lolcat
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'fortune-mod' instead of 'fortune'
The following additional packages will be installed:
  ca-certificates cowsay-off fonts-lato fortunes-min ifupdown iproute2
  isc-dhcp-client isc-dhcp-common javascript-common libatm1 libdns-export162
  libffi6 libgdbm3 libgmp10 libisc-export160 libjs-jquery libmnl0 libperl5.22
  librecode0 libruby2.3 libssl1.0.0 libtext-charwidth-perl libxtables11
  libyaml-0-2 netbase openssl perl perl-modules-5.22 rake rename ruby
  ruby-did-you-mean ruby-minitest ruby-net-telnet ruby-paint ruby-power-assert
  ruby-test-unit ruby-trollop ruby2.3 rubygems-integration unzip zip
Suggested packages:
  filters fortunes x11-utils bsdmainutils ppp rdnssd iproute2-doc resolvconf
  avahi-autoipd isc-dhcp-client-ddns apparmor apache2 | lighttpd | httpd
  perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make ri
  ruby-dev bundler
The following NEW packages will be installed:
  ca-certificates cowsay cowsay-off fonts-lato fortune-mod fortunes-min
  ifupdown iproute2 isc-dhcp-client isc-dhcp-common javascript-common libatm1
  libdns-export162 libffi6 libgdbm3 libgmp10 libisc-export160 libjs-jquery
  libmnl0 libperl5.22 librecode0 libruby2.3 libssl1.0.0 libtext-charwidth-perl
  libxtables11 libyaml-0-2 lolcat netbase openssl perl perl-modules-5.22 rake
  rename ruby ruby-did-you-mean ruby-minitest ruby-net-telnet ruby-paint
  ruby-power-assert ruby-test-unit ruby-trollop ruby2.3 rubygems-integration
  unzip zip
0 upgraded, 45 newly installed, 0 to remove and 0 not upgraded.
Need to get 17.2 MB of archives.
After this operation, 81.5 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libatm1 amd64 1:2.5.1-1.5 [24.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmnl0 amd64 1.0.3-5 [12.0 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 libgdbm3 amd64 1.8.3-13.1 [16.9 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 fonts-lato all 2.0-1 [2693 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 libyaml-0-2 amd64 0.1.6-3 [47.6 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 perl-modules-5.22 all 5.22.1-9ubuntu0.6 [2629 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libperl5.22 amd64 5.22.1-9ubuntu0.6 [3405 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 perl amd64 5.22.1-9ubuntu0.6 [237 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 iproute2 amd64 4.3.0-1ubuntu3.16.04.5 [523 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 ifupdown amd64 0.8.10ubuntu1.4 [54.9 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libisc-export160 amd64 1:9.10.3.dfsg.P4-8ubuntu1.15 [153 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libdns-export162 amd64 1:9.10.3.dfsg.P4-8ubuntu1.15 [665 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 isc-dhcp-client amd64 4.3.3-5ubuntu12.10 [224 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 isc-dhcp-common amd64 4.3.3-5ubuntu12.10 [105 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial/main amd64 libffi6 amd64 3.2.1-4 [17.8 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial/main amd64 libgmp10 amd64 2:6.1.0+dfsg-2 [240 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.15 [1084 kB]
Get:18 http://archive.ubuntu.com/ubuntu xenial/main amd64 libtext-charwidth-perl amd64 0.04-7build5 [9248 B]
Get:19 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxtables11 amd64 1.6.0-2ubuntu3 [27.2 kB]
Get:20 http://archive.ubuntu.com/ubuntu xenial/main amd64 netbase all 5.3 [12.9 kB]
Get:21 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssl amd64 1.0.2g-1ubuntu4.15 [492 kB]
Get:22 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 ca-certificates all 20170717~16.04.2 [167 kB]
Get:23 http://archive.ubuntu.com/ubuntu xenial/universe amd64 cowsay all 3.03+dfsg1-15 [18.0 kB]
Get:24 http://archive.ubuntu.com/ubuntu xenial/universe amd64 cowsay-off all 3.03+dfsg1-15 [3640 B]
Get:25 http://archive.ubuntu.com/ubuntu xenial/main amd64 librecode0 amd64 3.6-22 [523 kB]
Get:26 http://archive.ubuntu.com/ubuntu xenial/universe amd64 fortune-mod amd64 1:1.99.1-7 [39.5 kB]
Get:27 http://archive.ubuntu.com/ubuntu xenial/universe amd64 fortunes-min all 1:1.99.1-7 [61.8 kB]
Get:28 http://archive.ubuntu.com/ubuntu xenial/main amd64 javascript-common all 11 [6066 B]
Get:29 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjs-jquery all 1.11.3+dfsg-4 [161 kB]
Get:30 http://archive.ubuntu.com/ubuntu xenial/main amd64 rubygems-integration all 1.10 [4966 B]
Get:31 http://archive.ubuntu.com/ubuntu xenial/main amd64 ruby-did-you-mean all 1.0.0-2 [8390 B]
Get:32 http://archive.ubuntu.com/ubuntu xenial/main amd64 ruby-minitest all 5.8.4-2 [36.6 kB]
Get:33 http://archive.ubuntu.com/ubuntu xenial/main amd64 ruby-net-telnet all 0.1.1-2 [12.6 kB]
Get:34 http://archive.ubuntu.com/ubuntu xenial/main amd64 ruby-power-assert all 0.2.7-1 [7668 B]
Get:35 http://archive.ubuntu.com/ubuntu xenial/main amd64 ruby-test-unit all 3.1.7-2 [60.3 kB]
Get:36 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libruby2.3 amd64 2.3.1-2~ubuntu16.04.14 [2958 kB]
Get:37 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 ruby2.3 amd64 2.3.1-2~ubuntu16.04.14 [40.8 kB]
Get:38 http://archive.ubuntu.com/ubuntu xenial/main amd64 ruby all 1:2.3.0+1 [5530 B]
Get:39 http://archive.ubuntu.com/ubuntu xenial/main amd64 rake all 10.5.0-2 [48.2 kB]
Get:40 http://archive.ubuntu.com/ubuntu xenial/main amd64 rename all 0.20-4 [12.0 kB]
Get:41 http://archive.ubuntu.com/ubuntu xenial/main amd64 unzip amd64 6.0-20ubuntu1 [158 kB]
Get:42 http://archive.ubuntu.com/ubuntu xenial/main amd64 zip amd64 3.0-11 [158 kB]
Get:43 http://archive.ubuntu.com/ubuntu xenial/universe amd64 ruby-trollop all 2.0-2 [14.8 kB]
Get:44 http://archive.ubuntu.com/ubuntu xenial/universe amd64 ruby-paint all 0.8.6-1build1 [15.3 kB]
Get:45 http://archive.ubuntu.com/ubuntu xenial/universe amd64 lolcat all 42.0.99-1 [5514 B]
Fetched 17.2 MB in 4s (3617 kB/s) 
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libatm1:amd64.
(Reading database ... 4781 files and directories currently installed.)
Preparing to unpack .../libatm1_1%3a2.5.1-1.5_amd64.deb ...
Unpacking libatm1:amd64 (1:2.5.1-1.5) ...
Selecting previously unselected package libmnl0:amd64.
Preparing to unpack .../libmnl0_1.0.3-5_amd64.deb ...
Unpacking libmnl0:amd64 (1.0.3-5) ...
Selecting previously unselected package libgdbm3:amd64.
Preparing to unpack .../libgdbm3_1.8.3-13.1_amd64.deb ...
Unpacking libgdbm3:amd64 (1.8.3-13.1) ...
Selecting previously unselected package fonts-lato.
Preparing to unpack .../fonts-lato_2.0-1_all.deb ...
Unpacking fonts-lato (2.0-1) ...
Selecting previously unselected package libyaml-0-2:amd64.
Preparing to unpack .../libyaml-0-2_0.1.6-3_amd64.deb ...
Unpacking libyaml-0-2:amd64 (0.1.6-3) ...
Selecting previously unselected package perl-modules-5.22.
Preparing to unpack .../perl-modules-5.22_5.22.1-9ubuntu0.6_all.deb ...
Unpacking perl-modules-5.22 (5.22.1-9ubuntu0.6) ...
Selecting previously unselected package libperl5.22:amd64.
Preparing to unpack .../libperl5.22_5.22.1-9ubuntu0.6_amd64.deb ...
Unpacking libperl5.22:amd64 (5.22.1-9ubuntu0.6) ...
Selecting previously unselected package perl.
Preparing to unpack .../perl_5.22.1-9ubuntu0.6_amd64.deb ...
Unpacking perl (5.22.1-9ubuntu0.6) ...
Selecting previously unselected package iproute2.
Preparing to unpack .../iproute2_4.3.0-1ubuntu3.16.04.5_amd64.deb ...
Unpacking iproute2 (4.3.0-1ubuntu3.16.04.5) ...
Selecting previously unselected package ifupdown.
Preparing to unpack .../ifupdown_0.8.10ubuntu1.4_amd64.deb ...
Unpacking ifupdown (0.8.10ubuntu1.4) ...
Selecting previously unselected package libisc-export160.
Preparing to unpack .../libisc-export160_1%3a9.10.3.dfsg.P4-8ubuntu1.15_amd64.deb ...
Unpacking libisc-export160 (1:9.10.3.dfsg.P4-8ubuntu1.15) ...
Selecting previously unselected package libdns-export162.
Preparing to unpack .../libdns-export162_1%3a9.10.3.dfsg.P4-8ubuntu1.15_amd64.deb ...
Unpacking libdns-export162 (1:9.10.3.dfsg.P4-8ubuntu1.15) ...
Selecting previously unselected package isc-dhcp-client.
Preparing to unpack .../isc-dhcp-client_4.3.3-5ubuntu12.10_amd64.deb ...
Unpacking isc-dhcp-client (4.3.3-5ubuntu12.10) ...
Selecting previously unselected package isc-dhcp-common.
Preparing to unpack .../isc-dhcp-common_4.3.3-5ubuntu12.10_amd64.deb ...
Unpacking isc-dhcp-common (4.3.3-5ubuntu12.10) ...
Selecting previously unselected package libffi6:amd64.
Preparing to unpack .../libffi6_3.2.1-4_amd64.deb ...
Unpacking libffi6:amd64 (3.2.1-4) ...
Selecting previously unselected package libgmp10:amd64.
Preparing to unpack .../libgmp10_2%3a6.1.0+dfsg-2_amd64.deb ...
Unpacking libgmp10:amd64 (2:6.1.0+dfsg-2) ...
Selecting previously unselected package libssl1.0.0:amd64.
Preparing to unpack .../libssl1.0.0_1.0.2g-1ubuntu4.15_amd64.deb ...
Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu4.15) ...
Selecting previously unselected package libtext-charwidth-perl.
Preparing to unpack .../libtext-charwidth-perl_0.04-7build5_amd64.deb ...
Unpacking libtext-charwidth-perl (0.04-7build5) ...
Selecting previously unselected package libxtables11:amd64.
Preparing to unpack .../libxtables11_1.6.0-2ubuntu3_amd64.deb ...
Unpacking libxtables11:amd64 (1.6.0-2ubuntu3) ...
Selecting previously unselected package netbase.
Preparing to unpack .../archives/netbase_5.3_all.deb ...
Unpacking netbase (5.3) ...
Selecting previously unselected package openssl.
Preparing to unpack .../openssl_1.0.2g-1ubuntu4.15_amd64.deb ...
Unpacking openssl (1.0.2g-1ubuntu4.15) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20170717~16.04.2_all.deb ...
Unpacking ca-certificates (20170717~16.04.2) ...
Selecting previously unselected package cowsay.
Preparing to unpack .../cowsay_3.03+dfsg1-15_all.deb ...
Unpacking cowsay (3.03+dfsg1-15) ...
Selecting previously unselected package cowsay-off.
Preparing to unpack .../cowsay-off_3.03+dfsg1-15_all.deb ...
Unpacking cowsay-off (3.03+dfsg1-15) ...
Selecting previously unselected package librecode0:amd64.
Preparing to unpack .../librecode0_3.6-22_amd64.deb ...
Unpacking librecode0:amd64 (3.6-22) ...
Selecting previously unselected package fortune-mod.
Preparing to unpack .../fortune-mod_1%3a1.99.1-7_amd64.deb ...
Unpacking fortune-mod (1:1.99.1-7) ...
Selecting previously unselected package fortunes-min.
Preparing to unpack .../fortunes-min_1%3a1.99.1-7_all.deb ...
Unpacking fortunes-min (1:1.99.1-7) ...
Selecting previously unselected package javascript-common.
Preparing to unpack .../javascript-common_11_all.deb ...
Unpacking javascript-common (11) ...
Selecting previously unselected package libjs-jquery.
Preparing to unpack .../libjs-jquery_1.11.3+dfsg-4_all.deb ...
Unpacking libjs-jquery (1.11.3+dfsg-4) ...
Selecting previously unselected package rubygems-integration.
Preparing to unpack .../rubygems-integration_1.10_all.deb ...
Unpacking rubygems-integration (1.10) ...
Selecting previously unselected package ruby-did-you-mean.
Preparing to unpack .../ruby-did-you-mean_1.0.0-2_all.deb ...
Unpacking ruby-did-you-mean (1.0.0-2) ...
Selecting previously unselected package ruby-minitest.
Preparing to unpack .../ruby-minitest_5.8.4-2_all.deb ...
Unpacking ruby-minitest (5.8.4-2) ...
Selecting previously unselected package ruby-net-telnet.
Preparing to unpack .../ruby-net-telnet_0.1.1-2_all.deb ...
Unpacking ruby-net-telnet (0.1.1-2) ...
Selecting previously unselected package ruby-power-assert.
Preparing to unpack .../ruby-power-assert_0.2.7-1_all.deb ...
Unpacking ruby-power-assert (0.2.7-1) ...
Selecting previously unselected package ruby-test-unit.
Preparing to unpack .../ruby-test-unit_3.1.7-2_all.deb ...
Unpacking ruby-test-unit (3.1.7-2) ...
Selecting previously unselected package libruby2.3:amd64.
Preparing to unpack .../libruby2.3_2.3.1-2~ubuntu16.04.14_amd64.deb ...
Unpacking libruby2.3:amd64 (2.3.1-2~ubuntu16.04.14) ...
Selecting previously unselected package ruby2.3.
Preparing to unpack .../ruby2.3_2.3.1-2~ubuntu16.04.14_amd64.deb ...
Unpacking ruby2.3 (2.3.1-2~ubuntu16.04.14) ...
Selecting previously unselected package ruby.
Preparing to unpack .../ruby_1%3a2.3.0+1_all.deb ...
Unpacking ruby (1:2.3.0+1) ...
Selecting previously unselected package rake.
Preparing to unpack .../archives/rake_10.5.0-2_all.deb ...
Unpacking rake (10.5.0-2) ...
Selecting previously unselected package rename.
Preparing to unpack .../archives/rename_0.20-4_all.deb ...
Unpacking rename (0.20-4) ...
Selecting previously unselected package unzip.
Preparing to unpack .../unzip_6.0-20ubuntu1_amd64.deb ...
Unpacking unzip (6.0-20ubuntu1) ...
Selecting previously unselected package zip.
Preparing to unpack .../archives/zip_3.0-11_amd64.deb ...
Unpacking zip (3.0-11) ...
Selecting previously unselected package ruby-trollop.
Preparing to unpack .../ruby-trollop_2.0-2_all.deb ...
Unpacking ruby-trollop (2.0-2) ...
Selecting previously unselected package ruby-paint.
Preparing to unpack .../ruby-paint_0.8.6-1build1_all.deb ...
Unpacking ruby-paint (0.8.6-1build1) ...
Selecting previously unselected package lolcat.
Preparing to unpack .../lolcat_42.0.99-1_all.deb ...
Unpacking lolcat (42.0.99-1) ...
Processing triggers for systemd (229-4ubuntu21.23) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Setting up libatm1:amd64 (1:2.5.1-1.5) ...
Setting up libmnl0:amd64 (1.0.3-5) ...
Setting up libgdbm3:amd64 (1.8.3-13.1) ...
Setting up fonts-lato (2.0-1) ...
Setting up libyaml-0-2:amd64 (0.1.6-3) ...
Setting up perl-modules-5.22 (5.22.1-9ubuntu0.6) ...
Setting up libperl5.22:amd64 (5.22.1-9ubuntu0.6) ...
Setting up perl (5.22.1-9ubuntu0.6) ...
update-alternatives: using /usr/bin/prename to provide /usr/bin/rename (rename) in auto mode
Setting up iproute2 (4.3.0-1ubuntu3.16.04.5) ...
Setting up ifupdown (0.8.10ubuntu1.4) ...
Creating /etc/network/interfaces.
Setting up libisc-export160 (1:9.10.3.dfsg.P4-8ubuntu1.15) ...
Setting up libdns-export162 (1:9.10.3.dfsg.P4-8ubuntu1.15) ...
Setting up isc-dhcp-client (4.3.3-5ubuntu12.10) ...
Setting up isc-dhcp-common (4.3.3-5ubuntu12.10) ...
Setting up libffi6:amd64 (3.2.1-4) ...
Setting up libgmp10:amd64 (2:6.1.0+dfsg-2) ...
Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.15) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Setting up libtext-charwidth-perl (0.04-7build5) ...
Setting up libxtables11:amd64 (1.6.0-2ubuntu3) ...
Setting up netbase (5.3) ...
Setting up openssl (1.0.2g-1ubuntu4.15) ...
Setting up ca-certificates (20170717~16.04.2) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Setting up cowsay (3.03+dfsg1-15) ...
Setting up cowsay-off (3.03+dfsg1-15) ...
Setting up librecode0:amd64 (3.6-22) ...
Setting up fortune-mod (1:1.99.1-7) ...
Setting up fortunes-min (1:1.99.1-7) ...
Setting up javascript-common (11) ...
Setting up libjs-jquery (1.11.3+dfsg-4) ...
Setting up rubygems-integration (1.10) ...
Setting up ruby-did-you-mean (1.0.0-2) ...
Setting up ruby-minitest (5.8.4-2) ...
Setting up ruby-net-telnet (0.1.1-2) ...
Setting up ruby-power-assert (0.2.7-1) ...
Setting up ruby-test-unit (3.1.7-2) ...
Setting up rename (0.20-4) ...
update-alternatives: using /usr/bin/file-rename to provide /usr/bin/rename (rename) in auto mode
Setting up unzip (6.0-20ubuntu1) ...
Setting up zip (3.0-11) ...
Setting up rake (10.5.0-2) ...
Setting up libruby2.3:amd64 (2.3.1-2~ubuntu16.04.14) ...
Setting up ruby2.3 (2.3.1-2~ubuntu16.04.14) ...
Setting up ruby (1:2.3.0+1) ...
Setting up ruby-trollop (2.0-2) ...
Setting up ruby-paint (0.8.6-1build1) ...
Setting up lolcat (42.0.99-1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for systemd (229-4ubuntu21.23) ...
Processing triggers for ca-certificates (20170717~16.04.2) ...
Updating certificates in /etc/ssl/certs...
148 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
INFO:    Adding environment to container
INFO:    Adding runscript
INFO:    Creating SIF file...
INFO:    Build complete: lolcow.sif
Out[13]:
0

Options such as notest=True could be add to the action. Note that the content of the definition file is indented for clarify, but you can include the file as it is (no indentation).