Running Processes In A Podman Container

Article ID: 696
Last updated: 21 Nov, 2025

Note: When running on a compute node, you may need to run the command loginctl enable-linger your_nas_username prior to running the podman command. Otherwise, you may encounter the following error:

Error: default OCI runtime "crun" not found: invalid argument

After you prepare a Podman image for use on NAS systems, you can run a command in a new or existing (running) container. You can also bind-mount your home and/or nobackup filesystems to a Podman container.

Note: After you complete your runs, be sure to remove unwanted containers or images as described in the Limitations section of Getting Started with Podman at NAS.

Introduction

Use the podman run command and its options, followed by an image name or image ID, to run a command in a new container from an image. The following options are commonly used:

  • --interactive (or -i): to keep the standard input (STDIN) open even if not attached.
  • --tty or (-t): to allocate a pseudo-TTY for container.
  • --rm: to remove container and any anonymous unnamed volume associated with the container after exit.
  • --volume: to bind mount a volume into the container.
  • --workdir (or -w): to set working directory inside the container.
  • --env or (-e): to set environment variables in container.

To see more options, do:  podman run --help

To execute a command in a running container, use the podman exec command followed by its options and the name or ID of the container. Some of its options are the same as the podman run command options, such as -i, -t, -e, -w.

For more information, see:  podman exec -h

The examples shown in this article use a centos image pulled from quay.io:

% podman pull centos
% podman images
REPOSITORY             TAG         IMAGE ID      CREATED      SIZE
quay.io/centos/centos  latest      300e315adb2f  3 years ago  217 MB

If you want information about how this image was created, do (for example):

% podman inspect centos
or
% podman inspect 300e315adb2f 

Running a Command In a New Container From an Image

  • To run a container in an interactive mode followed by running a few commands:
    % podman run -it centos
    # whoami
    root
    # pwd
    /
    # echo $HOME
    /root
    # ls /root
    anaconda-ks.cfg  anaconda-post.log  original-ks.cfg

    Notes:

    • At the container prompt #, you may also see the containerID, for example, 550df871ae08#.
    • This centos image was created with CMD in its Containerfile set to /bin/bash. Therefore, without a specified command after podman run -it centos in the command line, /bin/bash is run.
    • To exit out of this interactive mode, type exit or use Ctrl-D.

  • To run a container with the ls command, then exit:
    % podman run centos ls
    
    or
    
    % podman run -it 300e315adb2f ls
    bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root ...

  • To run a container and remove it after exiting:

    A container that exited is still stored in /nasa2/your_nas_username/containers. Add the option --rm if you want to remove it from storage after exit.

    % podman run --rm -it centos 
    #

If you have a container already running on a host, you can find its containerID and name using any of the following (for example):

% podman container list

or 

% podman container ps

or

% podman ps

CONTAINER ID   IMAGE                         COMMAND   CREATED         
550df871ae08   quay.io/centos/centos:latest  bash      4 minutes ago       

STATUS         PORTS                         NAMES
Up 4 minutes                                 cool_lederberg

Note: By default, the above commands only show containers that are running. To see all containers in all states, add --all or -a.

Bind-Mounting a Volume When Running a New Container

  • To bind-mount your NAS /nobackup filesystem to the container and create a file foo:
    % podman run -v /nobackup/your_nas_username:/nobackup/your_nas_username -it centos
    # ls
    bin  dev  etc  home  lib  lib64  lost+found  media  mnt  nobackup  opt	proc ...
    # cd /nobackup/your_nas_username
    # vi foo

  • To bind-mount your NAS /nobackup filesystem as read-only, add :ro as follows:
    -v /nobackup/your_nas_username:/nobackup/your_nas_username:ro

  • Most likely, an image already contains a directory named /home which is not your NAS home filesystem. To bind-mount your NAS home filesystem, use /u/your_nas_username or /homeX/your_nas_username, where X is a number associated with your NAS $HOME. You can find which homeX is yours with the command ls ‑ld /u/your_nas_username before bind-mounting it to the container. For example:
    % ls -ld /u/your_nas_username
    lrwxrwxrwx 1 root root 14 Feb  1  2018 /u/your_nas_username -> /home4/your_nas_username
    % podman run -v /home4/your_nas_username:/home4/your_nas_username -it centos
    # ls
    bin  dev  etc  home  home4  lib  lib64	lost+found  media  mnt	opt  proc ...
    # cd /home4/your_nas_username

  • To bind-mount both your NAS home and /nobackup filesystems, issue -v one time for your NAS home filesystem, and another -v for your NAS /nobackup filesystem.

Executing a Command In a Running Container

WARNING: This section does not apply to containers running on a compute node via PBS.

You can execute commands in a running container from the same host where it was started (for example, pfe25), but not from other hosts.

  • Execute a command in the running container using either the name or the containerID of the container. For example:
    % podman exec cool_lederberg echo hello
    or
    % podman exec -it cool_lederberg echo hello
    or
    % podman exec -it 550df871ae08 echo hello
    hello

  • Access bind-mounted filesystem in a running container. For example:
    % podman exec -it cool_lederberg ls /nobackup/your_nas_username

  • Set the working directory to a bind-mounted filesystem in a running container. For example:
    % podman exec -w /nobackup/your_nas_username -it cool_lederberg bash
    # pwd
    /nobackup/your_nas_username

    Note: Similarly, you can set the working directory with the  podman run  command when starting a new container.

  • Modify an environment variable in a running container:

    The variable PATH is used as an example.

    By default, PATH in a Podman container is set to: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    The following example shows one method of modifying PATH. It assumes that the running container was created with your /homeX/your_nas_user_name bind-mounted and the containerID is 550df871ae08.

    • If you use csh:
      % setenv PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/ \
      sbin:/bin:/homeX/your_nas_username/bin"
    • If you use bash:
      % export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/ \
      sbin:/bin:/homeX/your_nas_username/bin"

    Note: The command lines above are too long to be formatted as one line, so they are broken with a backslash (\).

    Use the -e option to set PATH for the container:

    % podman exec -e PATH=$PATH -it 550df871ae08 bash
    # echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin: \
    /bin:/homeX/your_nas_username/bin

    Note: Similarly, you can set environment variables with the  podman run  command when starting a new container.

Running a Container With a Workflow In a Script

Likely, you want to run multiple commands or a complicated workflow in a container. You can create a script for this purpose. For example, under your NAS $HOME, create a script,  test.sh,  which contains:

#!/bin/bash

whoami
pwd
ls
cd /homeX/your_nas_username
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin: \
/usr/bin:/sbin:/bin:/homeX/your_nas_username/bin"
echo $PATH

Run test.sh to make sure the script can be executed:

% chmod u+x test.sh

When running a container, bind-mount your NAS $HOME and add test.sh as the command to be executed. For example:

% podman run -it -v /homeX/name:/homeX/name centos /homeX/name/test.sh

or

% podman run -it -v /homeX/name:/homeX/name -w /homeX/name centos ./test.sh
Also read

Contact Us

General User Assistance

Security

  • Report security issues 24x7x365
  • Toll-free: 1-877-NASA-SEC (1-877-627-2732)
  • E-mail: soc@nasa.gov

User Documentation

High-End Computing Capability (HECC) Portfolio Office

NASA High-End Computing Program

Tell Us About It

Our goal is furnish all the information you need to efficiently and effectively use the HECC resources needed for your NASA computational projects.

We welcome your input on features and topics that you would like to see included on this website.

Please send us email with your wish list and other feedback.