diff --git a/workshop/1_start-an-app.ipynb b/workshop/1_start-an-app.ipynb
index 7dd0f75393dd95d85fbe6bbcacce3cc9067add14..ca7d8050ddc12f8e82db9b820d30b8dbfa8bbd67 100644
--- a/workshop/1_start-an-app.ipynb
+++ b/workshop/1_start-an-app.ipynb
@@ -162,7 +162,6 @@
    "source": [
     "%%writefile {xpublish_example_script}\n",
     "\n",
-    "port=9010\n",
     "ssl_keyfile=\"/work/bm0021/k204210/cloudify/workshop/key.pem\"\n",
     "ssl_certfile=\"/work/bm0021/k204210/cloudify/workshop/cert.pem\"\n",
     "\n",
@@ -175,7 +174,20 @@
     "import nest_asyncio\n",
     "import sys\n",
     "import os\n",
+    "def is_port_free(port, host=\"localhost\"):\n",
+    "    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n",
+    "        return s.connect_ex((host, port)) != 0  # Returns True if the port is free\n",
     "\n",
+    "def find_free_port(start=5000, end=5100, host=\"localhost\"):\n",
+    "    for port in range(start, end + 1):\n",
+    "        if is_port_free(port, host):\n",
+    "            return port\n",
+    "    return None  # No free ports found\n",
+    "\n",
+    "port = find_free_port(9000,9100)\n",
+    "if not port:\n",
+    "    raise ValueError(\"Could not find a free port for service\")\n",
+    "    \n",
     "nest_asyncio.apply()\n",
     "chunks={}\n",
     "for coord in [\"lon\",\"lat\"]:\n",
diff --git a/workshop/4_kerchunk-input-kerchunk-api.ipynb b/workshop/4_kerchunk-input-kerchunk-api.ipynb
index 04355c0c1ef799f7a129c5161f1cbe1176d9ae90..eccf99d16c4b689ed64db8396d1de41ddb41aff3 100644
--- a/workshop/4_kerchunk-input-kerchunk-api.ipynb
+++ b/workshop/4_kerchunk-input-kerchunk-api.ipynb
@@ -53,7 +53,6 @@
    "source": [
     "%%writefile xpublish_references.py\n",
     "\n",
-    "port=9010\n",
     "ssl_keyfile=\"/work/bm0021/k204210/cloudify/workshop/key.pem\"\n",
     "ssl_certfile=\"/work/bm0021/k204210/cloudify/workshop/cert.pem\"\n",
     "\n",
@@ -66,7 +65,20 @@
     "import nest_asyncio\n",
     "import sys\n",
     "import os\n",
+    "def is_port_free(port, host=\"localhost\"):\n",
+    "    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n",
+    "        return s.connect_ex((host, port)) != 0  # Returns True if the port is free\n",
+    "\n",
+    "def find_free_port(start=5000, end=5100, host=\"localhost\"):\n",
+    "    for port in range(start, end + 1):\n",
+    "        if is_port_free(port, host):\n",
+    "            return port\n",
+    "    return None  # No free ports found\n",
     "\n",
+    "port = find_free_port(9000,9100)\n",
+    "if not port:\n",
+    "    raise ValueError(\"Could not find a free port for service\")\n",
+    "    \n",
     "nest_asyncio.apply()\n",
     "\n",
     "if __name__ == \"__main__\":  # This avoids infinite subprocess creation\n",
diff --git a/workshop/5_catalog-input.ipynb b/workshop/5_catalog-input.ipynb
index 481fe5d8b518f6c2ff70ccdc33c112643e3e079e..ac4c931d17cbaca37424969d1db8c7bfdaf7d0cc 100644
--- a/workshop/5_catalog-input.ipynb
+++ b/workshop/5_catalog-input.ipynb
@@ -29,7 +29,6 @@
    "source": [
     "%%writefile xpublish_spoi.py\n",
     "\n",
-    "port=9000\n",
     "ssl_keyfile=\"/work/bm0021/k204210/cloudify/workshop/key.pem\"\n",
     "ssl_certfile=\"/work/bm0021/k204210/cloudify/workshop/cert.pem\"\n",
     "\n",
@@ -43,7 +42,20 @@
     "import sys\n",
     "import os\n",
     "import intake\n",
+    "def is_port_free(port, host=\"localhost\"):\n",
+    "    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n",
+    "        return s.connect_ex((host, port)) != 0  # Returns True if the port is free\n",
+    "\n",
+    "def find_free_port(start=5000, end=5100, host=\"localhost\"):\n",
+    "    for port in range(start, end + 1):\n",
+    "        if is_port_free(port, host):\n",
+    "            return port\n",
+    "    return None  # No free ports found\n",
     "\n",
+    "port = find_free_port(9000,9100)\n",
+    "if not port:\n",
+    "    raise ValueError(\"Could not find a free port for service\")\n",
+    "    \n",
     "nest_asyncio.apply()\n",
     "STORAGE_OPTIONS=dict(\n",
     "    cache_size=0\n",