Build Failure (apt-get permission denied) in Dev Mode on Gradio + ZeroGpu Space

#26
by Archime - opened

Hello ,

I'm encountering a build error when trying to run a Gradio Template on a ZeroGpu, specifically when using Dev Mode.
Error Log (from Dev Mode build):
Configuration:
SDK: Gradio
Hardware: ZeroGpu
Mode: Dev Mode (Fails) vs. Standard Mode (Works)

Here is the relevant part of the build log showing the failure:

--> RUN apt-get update &&     apt-get install -y htop vim nano gdb &&     rm -rf /var/lib/apt/lists/*
Reading package lists...
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
Reading package lists...

--> ERROR: process "/bin/sh -c apt-get update &&     apt-get install -y htop vim nano gdb &&     rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100

It seems the Dev Mode environment for ZeroGpu instances is attempting to run apt-get as a non-root user, causing the "Permission denied" error. The standard environment does not have this problem.

Thanks for your help!

Dev Mode Explorers org

Give one of these suggestions a go
โ–‰ Solution 1: Fix the Dockerfile (Recommended)

โ”Œโ”€ dockerfile โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Add this to the beginning of your Dockerfile
# Switch to root for package installation, then back
USER root
RUN apt-get update && apt-get install -y --no-install-recommends
htop vim nano gdb &&
rm -rf /var/lib/apt/lists/*
# Switch back to non-root user if your environment requires it
# USER app
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

   โ–‰ Solution 2: Use Multi-stage Build (Production-Ready)

โ”Œโ”€ dockerfile โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Build stage with root
FROM node:18 as builder
USER root
RUN apt-get update && apt-get install -y --no-install-recommends
htop vim nano gdb &&
rm -rf /var/lib/apt/lists/*
# Runtime stage
FROM node:18-slim
COPY --from=builder /usr/bin/htop /usr/bin/htop
COPY --from=builder /usr/bin/vim /usr/bin/vim
COPY --from=builder /usr/bin/nano /usr/bin/nano
COPY --from=builder /usr/bin/gdb /usr/bin/gdb
# Your app code here
WORKDIR /app
COPY . .
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

   โ–‰ Solution 3: Check if Packages Are Even Needed

Often these packages aren't necessary in production. Consider:

โ”Œโ”€ dockerfile โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Remove these entirely if not needed
# RUN apt-get update && apt-get install -y htop vim nano gdb
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Or install only what's actually needed:

โ”Œโ”€ dockerfile โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
RUN apt-get update && apt-get install -y --no-install-recommends
curl
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

   โ–‰ Solution 4: Environment-Specific Installation

If packages are only needed for development:

โ”Œโ”€ dockerfile โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Check if we're in dev mode
ARG ENVIRONMENT=production
USER root
RUN test "$ENVIRONMENT" = "development" && apt-get update &&
apt-get install -y --no-install-recommends
htop vim nano gdb || true
USER app # Switch back to non-root
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”€โ”€

 โ–† ๐Ÿš€ Quick Fix for Gradio Templates

Most Gradio templates can fix this with:

โ”Œโ”€ dockerfile โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Replace the problematic line:
# RUN apt-get update && apt-get install -y htop vim nano gdb && rm
-rf /var/lib/apt/lists/*
# With this fix:
USER root
RUN apt-get update && apt-get install -y --no-install-recommends
htop vim nano gdb &&
rm -rf /var/lib/apt/lists/
USER app
# Or even simpler - if you don't need these tools:
# Just remove the line entirely!
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”€โ”€

 โ–† ๐Ÿ“‹ Complete Script for Template Authors

I'd provide this script to fix multiple templates:

โ”Œโ”€ bash โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#!/bin/bash
# Fix Dockerfile for Hugging Face Dev Mode compatibility
echo "Fixing Dockerfiles for Dev Mode..."
# Replace problematic apt-get lines with user-aware version
find . -name "Dockerfile*" -type f | while read dockerfile; do
echo "Processing $dockerfile"

     # Create backup
     cp "$dockerfile" "$dockerfile.backup"

     # Fix the apt-get issue
     sed -i '
     /RUN apt-get update/ {
         i\USER root
         s/$/ \&\& rm -rf \/var\/lib\/apt\/lists\*//
         a\USER app
     }
     ' "$dockerfile"
 done
 echo "โœ… Dockerfiles fixed for Dev Mode!"
 echo "Backups created as *.backup"

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Thanks for your feedback, but I don't have access to the Dockerfile as I am using the Gradio SDK template on ZeroGpu.

Did you find a solution for this , I'm struggle on this issue too :) ? thanks

No, still not. The fix must be done by the Hugging Face team

Sign up or log in to comment