Setting up ComfyUI in a Podman container on Fedora Linux with a Nvidia GPU.
Prepare Persistent Directories
Create directories on your host machine to store your models, custom nodes, outputs, and user data. This ensures your configurations and large model files survive container restarts and updates.
mkdir -p ~/comfyui/{models,custom_nodes,output,user}Create the Container Image
We will build a custom image based on Debian (python:3.11-slim).
Note: We explicitly include the GNU C-compilers (gcc, g++) via apt. This is required because the Triton library (used by PyTorch) needs to dynamically compile GPU kernels when ComfyUI starts. Without them, Triton will throw a 0 active drivers error.
Create a file named Containerfile in your current directory with the following contents:
# Use a slim Python 3.11 image as the base (Debian-based)
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies (including C compilers for Triton and OpenGL for OpenCV)
RUN apt-get update && apt-get install -y \
git \
libgl1 \
libglib2.0-0 \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Clone the latest ComfyUI repository
RUN git clone https://github.com/comfyanonymous/ComfyUI.git .
# Install PyTorch with CUDA 13.0 support (Required for RTX 50-series)
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130
# Install standard ComfyUI dependencies
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8188
# Bind to 0.0.0.0 so the host network can access the web interface
CMD ["python", "main.py", "--listen", "0.0.0.0"]Build the image using Podman:
podman build -t comfyui-nvidia .Deploy the Container
Run the container using the configuration below.
Critical Fedora-Specific Flags to Note:
--security-opt label=disable: This disables SELinux separation specifically for this container, preventing SELinux from blocking the execution of the injected Nvidia driver binaries (libcuda.so).:Z(on volume mounts): Instructs Podman to label the mounted host directories with a private unconfined SELinux context, allowing the container read/write access.
podman run -d \
--name comfyui \
--security-opt label=disable \
--device nvidia.com/gpu=all \
-p 8188:8188 \
-v ~/comfyui/models:/app/models:Z \
-v ~/comfyui/custom_nodes:/app/custom_nodes:Z \
-v ~/comfyui/output:/app/output:Z \
-v ~/comfyui/user:/app/user:Z \
localhost/comfyui-nvidiaAutomate Firewall for Remote Access (Optional)
If you want to access ComfyUI from another device on your network, you must open port 8188 in Fedora's firewall. Instead of leaving the port open permanently, you can use a wrapper script that temporarily opens it when ComfyUI starts, and securely closes it when the container stops.
Create a file named start_comfyui.sh:
#!/bin/bash
echo "Opening firewall port 8188..."
sudo firewall-cmd --add-port=8188/tcp
echo "Starting ComfyUI container..."
# The --attach flag keeps the script running until the container is stopped
podman start --attach comfyui
echo "Container stopped. Closing firewall port..."
sudo firewall-cmd --remove-port=8188/tcpMake the script executable and run it whenever you want to start your server for remote access:
chmod +x start_comfyui.sh
./start_comfyui.shAccess and Day-to-Day Management
Once deployed, you can access the ComfyUI web interface by opening your browser and navigating to:http://localhost:8188 (or your machine's local IP address if accessing from another device on the network).
Useful Podman Commands
- Check Startup Logs: Monitor the initialization process or kernel compilations:
podman logs -f comfyui - Stop the Server:
podman stop comfyui - Start the Server:
podman start comfyui - Clean up Disk Space: After rebuilding images (e.g., updating ComfyUI in the future), run this to delete dangling, unnamed images and recover gigabytes of storage space:
podman image prune
No comments:
Post a Comment