Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2024 22:51
Show Gist options
  • Save sourishkrout/b175b3ed48715b3157a17b037add3282 to your computer and use it in GitHub Desktop.
Save sourishkrout/b175b3ed48715b3157a17b037add3282 to your computer and use it in GitHub Desktop.

File name:

Session: 01HW40094TDKV7141FP619GGHG

▶️ Generated by Runme

Share your own terminal sessions, it's free and open source. Click here to learn more.

id version document session
id updated
2024-04-22 18:51:13 -0400

Runme Language Support

By default Runme can run everything that is also installed on your machine.

Shebang is a versatile tool designed to execute scripts written in various scripting languages including Shell, Perl, Python, Ruby, Node.js, and more. Runme integrates Shebang to enable users to run the script of their choice directly from the Markdown file in their preferred programming language.

Let's learn how to use multiple programming languages to interact with your containers!

In this example we will write a simple script in different programming languages that lists your running containers.

💡 Before starting, ensure you have the following installed in your machine:

  • Docker 🐳
  • Python 🐍 (for Python example)
  • GCP ☁️

Ensure docker is up and running

Run the following check, just to ensure you have Docker up and running


# Check if Docker is installed
if ! command -v docker &> /dev/null
    echo "Docker is not installed."

# Check if Docker daemon is running
if ! docker info &> /dev/null
    echo "Docker daemon is not running. ❌"

echo "Docker is installed and running. ✅"

# Ran on 2024-04-22 18:50:01-04:00 for 418ms exited with 0
Docker is installed and running. ✅

Ensure you have a list one container to list, if you don't have one, you can start a nginx container by running the following command:

docker rm -f my_runme_demo_container
docker run -d --name my_runme_demo_container -p 8080:80 nginx

# Ran on 2024-04-22 18:50:05-04:00 for 653ms exited with 0

Python 🐍


  • Ensure you have python installed
  • Create a virtual env
  • Install the docker and prettytable packages
python3 -m venv .venv
source .venv/bin/activate
pip3 install docker prettytable

# Ran on 2024-04-22 18:50:08-04:00 for 1.57s exited with 0
Requirement already satisfied: docker in ./.venv/lib/python3.12/site-packages (7.0.0)
Requirement already satisfied: prettytable in ./.venv/lib/python3.12/site-packages (3.10.0)
Requirement already satisfied: packaging>=14.0 in ./.venv/lib/python3.12/site-packages (from docker) (24.0)
Requirement already satisfied: requests>=2.26.0 in ./.venv/lib/python3.12/site-packages (from docker) (2.31.0)
Requirement already satisfied: urllib3>=1.26.0 in ./.venv/lib/python3.12/site-packages (from docker) (2.2.1)
Requirement already satisfied: wcwidth in ./.venv/lib/python3.12/site-packages (from prettytable) (0.2.13)
Requirement already satisfied: charset-normalizer<4,>=2 in ./.venv/lib/python3.12/site-packages (from requests>=2.26.0->docker) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in ./.venv/lib/python3.12/site-packages (from requests>=2.26.0->docker) (3.7)
Requirement already satisfied: certifi>=2017.4.17 in ./.venv/lib/python3.12/site-packages (from requests>=2.26.0->docker) (2024.2.2)

Now you have all the requirements ready, run the following Python script to get a list of running containers in a nice table format.

import docker
from prettytable import PrettyTable

def list_running_containers():
    client = docker.from_env()
    containers = client.containers.list()

    if containers:
        table = PrettyTable(["Container ID", "Name", "Image", "Status"])
        for container in containers:
            table.add_row([[:12],, container.attrs['Config']['Image'], container.status])
        print("Running containers:")
        print("No running containers found.")

if __name__ == "__main__":

# Ran on 2024-04-22 18:50:13-04:00 for 258ms exited with 0
Running containers:
| Container ID |              Name              |               Image               |  Status |
| 7832eb302419 |    my_runme_demo_container     |               nginx               | running |
| 27141269e2a4 | dagger-engine-9cf4d4ecdf5b646b | | running |

GCP ☁️

gcloud compute ssh --zone "us-central1-c" "gke-cluster-2-default-pool-78142957-e0ab" --project "runme-ci"

# Ran on 2024-04-22 18:50:28-04:00 for 2.044s
sourishkrout@gke-cluster-2-default-pool-78142957-e0ab ~ $ free -m
               total        used        free      shared  buff/cache   available
Mem:            3928         529        2158          54        1240        3104
Swap:              0           0           0
sourishkrout@gke-cluster-2-default-pool-78142957-e0ab ~ $ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment