diff --git a/llama-index-legacy/tests/initialization/postgres/Dockerfile b/llama-index-legacy/tests/initialization/postgres/Dockerfile
index bed56110891015594c3b0670205a174f0184cada..842244d2fc30582e7fcda25e41e4aee9d15787d7 100644
--- a/llama-index-legacy/tests/initialization/postgres/Dockerfile
+++ b/llama-index-legacy/tests/initialization/postgres/Dockerfile
@@ -1,4 +1,4 @@
 FROM postgres:latest
 
-RUN apt update && \
-    apt install -y git make gcc postgresql-16-pgvector
+RUN apt-get update -y && \
+    apt-get install -y git make gcc postgresql-16-pgvector
diff --git a/llama-index-networks/examples/demo/contributor-1/Dockerfile b/llama-index-networks/examples/demo/contributor-1/Dockerfile
index 598b16d42e4d85acd8f602454cd9fef123970fe4..14331111095015841c6b61244c09261761abd0e2 100644
--- a/llama-index-networks/examples/demo/contributor-1/Dockerfile
+++ b/llama-index-networks/examples/demo/contributor-1/Dockerfile
@@ -5,10 +5,9 @@ WORKDIR /app
 ENV POETRY_VERSION=1.7.1
 
 # Install libraries for necessary python package builds
-RUN apt-get update && apt-get install build-essential python3-dev libpq-dev -y
-
-RUN pip install --upgrade pip
-RUN pip install --upgrade poetry==${POETRY_VERSION}
+RUN apt-get update && apt-get --no-install-recommends install build-essential python3-dev libpq-dev -y && \
+    pip install --no-cache-dir --upgrade pip && \
+    pip install --no-cache-dir --upgrade poetry==${POETRY_VERSION}
 
 # Configure Poetry
 ENV POETRY_CACHE_DIR=/tmp/poetry_cache
@@ -23,7 +22,9 @@ RUN poetry install --no-cache --no-root
 
 FROM --platform=linux/amd64 python:3.10-slim as runtime
 
-RUN apt-get update && apt-get install libpq5 -y && rm -rf /var/lib/apt/lists/*  # Install libpq for psycopg2
+RUN apt-get update -y && \
+    apt-get install --no-install-recommends libpq5 -y && \
+    rm -rf /var/lib/apt/lists/*  # Install libpq for psycopg2
 
 RUN groupadd -r appuser && useradd --no-create-home -g appuser -r appuser
 USER appuser
diff --git a/llama-index-networks/examples/demo/contributor-2/Dockerfile b/llama-index-networks/examples/demo/contributor-2/Dockerfile
index f9811d982e736198ad45bd625810fb5eb5c46935..dd010b3d6361ccebf558dd2b0cdf5eed0fa6af90 100644
--- a/llama-index-networks/examples/demo/contributor-2/Dockerfile
+++ b/llama-index-networks/examples/demo/contributor-2/Dockerfile
@@ -5,10 +5,9 @@ WORKDIR /app
 ENV POETRY_VERSION=1.7.1
 
 # Install libraries for necessary python package builds
-RUN apt-get update && apt-get install build-essential python3-dev libpq-dev -y
-
-RUN pip install --upgrade pip
-RUN pip install --upgrade poetry==${POETRY_VERSION}
+RUN apt-get update && apt-get install --no-install-recommends build-essential python3-dev libpq-dev -y && \
+    pip install --no-cache-dir --upgrade pip && \
+    pip install --no-cache-dir --upgrade poetry==${POETRY_VERSION}
 
 # Configure Poetry
 ENV POETRY_CACHE_DIR=/tmp/poetry_cache
@@ -23,7 +22,9 @@ RUN poetry install --no-cache --no-root
 
 FROM --platform=linux/amd64 python:3.10-slim as runtime
 
-RUN apt-get update && apt-get install libpq5 -y && rm -rf /var/lib/apt/lists/*  # Install libpq for psycopg2
+RUN apt-get update &&  \
+    apt-get install --no-install-recommends libpq5 -y &&  \
+    rm -rf /var/lib/apt/lists/*  # Install libpq for psycopg2
 
 RUN groupadd -r appuser && useradd --no-create-home -g appuser -r appuser
 USER appuser