Is it possible to run slurm commands within a singularity container?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Yes, you can run Slurm commands from inside a Singularity container, but only if the container has access to compatible Slurm client tools and to the host environment that defines the current job context. In HPC practice, the more common pattern is to use Slurm on the host to allocate resources and then launch the container inside that allocation. Running sbatch, srun, or squeue inside the container is possible, but it is not something the container provides automatically.
Understand the Responsibility Split
Slurm is the scheduler for the cluster. Singularity, now commonly called Apptainer in many environments, packages the application runtime. Those are different layers of the stack.
A healthy mental model is:
- Slurm decides where your job runs
- the container defines what software runs there
- the host cluster still owns authentication, cgroups, and scheduler state
So when people ask whether Slurm commands can run inside the container, the real answer is: only if the container can talk to the same host-side Slurm installation and has the expected credentials, configuration, and environment variables.
The Common Pattern: Slurm Outside, Container Inside
The simplest and most portable workflow is to submit with Slurm on the host, then execute the application in the container.
In this model, the container does not need to submit jobs. It only runs inside an existing job allocation. The environment variables such as SLURM_JOB_ID are typically inherited, so the code inside the container can still detect the allocation.
That is the preferred solution when the goal is just to run containerized code on a Slurm-managed cluster.
Running squeue or sbatch Inside the Container
If you specifically want Slurm client commands inside the container, a few pieces must line up:
- the container must contain compatible Slurm client binaries, or bind them from the host
- the Slurm configuration such as
slurm.confmust be visible - the network path to
slurmctldand other services must be reachable - authentication such as Munge must work in the execution environment
A practical example is binding host configuration and running a shell inside the container:
Whether that works depends heavily on site policy. Some clusters intentionally avoid exposing all scheduler internals inside containers.
Why Compatibility Matters
Slurm commands are not just plain executables. They must speak to the site's Slurm control plane, often with version-sensitive behavior. If your image contains a mismatched Slurm client version, commands may fail even though networking and configuration are present.
That is why many HPC sites prefer one of these two patterns:
- install Slurm only on the host and run Slurm commands there
- bind host Slurm binaries and config into the container instead of packaging your own copy
The second approach reduces version drift, though it makes the container less self-contained.
A Practical Job Script Example
Here is a more realistic Slurm submission script that keeps scheduling outside the container while letting the application inspect Slurm variables inside it.
This is usually what users actually need: not submission from inside the container, but awareness of the Slurm allocation while running containerized software.
When Submission from Inside the Container Makes Sense
Submitting jobs from inside a container can be justified for workflow tools that expect to call sbatch directly. If you go that route, talk to the cluster administrators first. Scheduler access, Munge sockets, and config exposure are site-level security decisions, not just container tweaks.
In other words, the question is not only technical. It is also operational and policy-driven.
Common Pitfalls
The biggest mistake is assuming that because the container can run on a Slurm node, it automatically has working Slurm client access. It does not.
Another mistake is packaging a random Slurm client version inside the image and expecting it to match the cluster's controller version.
People also forget that authentication and configuration matter. Without the right slurm.conf, Munge integration, and network access, squeue and sbatch will fail.
Finally, many users are solving the wrong problem. If all you need is to run an application under Slurm, submit on the host and run the container inside the allocation.
Summary
- Yes, Slurm commands can run inside a Singularity or Apptainer container, but only with compatible client access and host integration
- The standard HPC pattern is to submit with Slurm on the host and execute the workload inside the container
- Slurm environment variables are usually available inside the container when launched from a Slurm job
- Running
squeueorsbatchinside the container requires configuration, authentication, and version compatibility - Binding host Slurm binaries and config is often safer than shipping your own mismatched client
- If the goal is only to run code on the cluster, keep scheduling outside the container

