How to Install ComfyUI in Docker with GPU Access for Local Image Generation
A spare GPU sitting in a PC or a VPS is an invitation. You want images generated on hardware you control, without queuing behind a paid service and without sending every prompt to somebody else's server. ComfyUI fits that job because its interface is a graph: loading a model, writing a prompt, sampling, and decoding are visible boxes wired together, so when an output goes wrong you can trace which step to blame.
One clarification matters before anything else. The official ComfyUI repository ships no official Docker image. This guide therefore does not ask you to pull a third-party image that cannot be verified here. Instead, you build your own image from the official repository, using install commands taken from its own documentation. You end up knowing exactly what went into the container, and you can rebuild it whenever you like.
Before you start
- A Linux machine with an NVIDIA GPU and a working NVIDIA driver. Run
nvidia-smion the host and confirm your card shows up. - Docker and Docker Compose installed.
- The NVIDIA Container Toolkit installed on the host, so Docker can pass the GPU into the container. Without it, the container only sees the CPU, and any GPU flag or Compose GPU reservation will fail.
- Plenty of disk space. Image models are large, and a single checkpoint can run to several gigabytes. Keep models in a mounted volume, not baked into the image layer, so they survive when the container is removed and rebuilt.
- Internet access for the first build, which downloads the repository, PyTorch, and the remaining dependencies.
The official docs note that Python 3.13 is well supported, and for NVIDIA users the stable PyTorch install uses the CUDA 13.0 index. Those two facts anchor the Dockerfile below.
Step 1: Create the project folder
Make one working folder, for example ~/comfyui-docker, with subfolders for the data that must outlive the container:
mkdir -p ~/comfyui-docker/models ~/comfyui-docker/output ~/comfyui-docker/input ~/comfyui-docker/custom_nodes
cd ~/comfyui-docker
Those folders get mounted into the container. Checkpoints, generated images, and custom nodes then live on the host even if the container is deleted. The layout mirrors ComfyUI's own folders: checkpoints belong in models/checkpoints, a separate VAE goes in models/vae, and finished images land in output.
Step 2: Write a Dockerfile based on the official repository
Create a file called Dockerfile in the project folder:
FROM python:3.13
WORKDIR /app
RUN apt-get update \
&& apt-get install -y git \
&& rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/comfyanonymous/ComfyUI.git .
RUN pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu130
RUN pip install -r requirements.txt
EXPOSE 8188
CMD ["python", "main.py", "--listen", "0.0.0.0", "--port", "8188"]
Each line traces back to official documentation. The clone targets the official comfyanonymous/ComfyUI repository. The PyTorch line uses the cu130 index, matching the NVIDIA instructions in the official README. The pip install -r requirements.txt line comes from the README's dependencies section. python main.py is the documented way to launch ComfyUI, and the official Startup Flags page documents --listen and --port: the default port is 8188, and --listen with no value listens on every interface.
Listening on 0.0.0.0 inside the container is deliberate. The container must accept connections on its internal interfaces for Docker's port mapping to work. Outside access is locked down on the host side in the next step, by binding the published port to localhost only.
Step 3: Add Compose configuration and start the stack
Create docker-compose.yml in the same folder:
services:
comfyui:
build: .
container_name: comfyui
ports:
- "127.0.0.1:8188:8188"
volumes:
- ./models:/app/models
- ./output:/app/output
- ./input:/app/input
- ./custom_nodes:/app/custom_nodes
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
restart: unless-stopped
Then build and start it:
docker compose build
docker compose up -d
docker compose logs -f comfyui
The first build takes a while because PyTorch and the dependencies download from scratch. Wait until the logs show the ComfyUI server running and listening on port 8188. If the log ends in an error, read that last block before deleting anything — nearly every install problem announces itself there.
Step 4: Open the interface and install a model
Open http://127.0.0.1:8188 in a browser on the same machine. Because the host side binds to 127.0.0.1, the interface is not exposed to your local network. If you are working on a remote VPS, do not open this port to the internet without an authentication layer in front of it, such as a reverse proxy. SSH port forwarding is the safer route.
Before your first generation, you need at least one checkpoint. Copy a .safetensors checkpoint file to the host folder:
~/comfyui-docker/models/checkpoints/your-model-name.safetensors
If your model uses a separate VAE, place it here:
~/comfyui-docker/models/vae/
Then restart the container if the model list has not picked the file up yet:
docker compose restart comfyui
Step 5: Build your first workflow
The default ComfyUI workflow is ready to run. Walk through each node before queuing, so a disappointing result points at a specific suspect:
- Load Checkpoint — loads a checkpoint from
models/checkpoints. An empty list means step 4 needs revisiting: check the folder and the file extension. - CLIP Text Encode, positive and negative — two text nodes. The positive one describes the image you want; the negative one lists what to avoid.
- Empty Latent Image — sets the image size and the batch count. Start with a moderate size and a batch of 1, especially on a card with limited VRAM.
- KSampler — where sampling happens. It takes the model, both prompts, and the empty latent, then runs the diffusion process with your seed, step count, and CFG value.
- VAE Decode — turns the sampled latent into a viewable image.
- Save Image — writes the result to
output, already mounted to./outputon the host.
Press Ctrl + Enter to queue the workflow. That shortcut, along with Ctrl + S to save a workflow, is documented in the official README. While the job runs, the queue panel shows progress node by node. A finished image appears in the Save Image node and as a file in ~/comfyui-docker/output.
Step 6: Save the workflow, then change one thing at a time
Once an image comes out, save the workflow with Ctrl + S. ComfyUI workflows are JSON files, so you can reopen them, share them, or load them again from the menu. For variations, change a single variable per run: the seed first, then the prompt, then the step count. Changing three at once leaves you unable to answer the question that matters most — which change actually improved the picture.
If you later want ComfyUI-Manager, the official README documents the path: install its dependencies with pip install -r manager_requirements.txt and launch with the --enable-manager flag. In this Docker setup, add both to your Dockerfile, rebuild the image, and start again. Treat custom nodes with the same caution you would any code running on your machine, and read what a node does before installing it from an unfamiliar source.
When something breaks
- The container runs but sees no GPU. Check
nvidia-smion the host first. If the card is missing there, the problem is the driver, not ComfyUI. If it shows on the host but not in the container, revisit the NVIDIA Container Toolkit install and the GPU reservation in Compose. - "Torch not compiled with CUDA enabled". The official README gives the fix: remove torch with
pip uninstall torch, then reinstall it with the CUDA 13.0 PyTorch command above. In Docker terms, that means fixing the Dockerfile, rebuilding, and starting again. - Port 8188 is already taken. Change only the host side of the mapping, for example
"127.0.0.1:8189:8188", and open port 8189 instead. The container side stays on 8188. - The checkpoint list is empty. Recheck the mount and confirm the file really sits in
~/comfyui-docker/models/checkpoints, not in another subfolder or inside a container that has since been removed. - A generation dies midway or the container stops. Read
docker compose logs comfyuifrom the bottom up. A memory error usually means VRAM ran out; shrink the image, drop the batch to 1, or restart with the documented--lowvramflag from the Startup Flags page.
Summary
| Piece | Path or command | What it does |
|---|---|---|
| Official repository | https://github.com/comfyanonymous/ComfyUI | The source cloned in the Dockerfile |
| NVIDIA PyTorch | pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu130 | PyTorch with CUDA 13.0 support |
| Dependencies | pip install -r requirements.txt | ComfyUI dependencies from the official repo |
| Launch command | python main.py --listen 0.0.0.0 --port 8188 | Starts the server inside the container |
| Web interface | http://127.0.0.1:8188 | Address to open on the same machine |
| Checkpoints | models/checkpoints | Where .safetensors model files go |
| VAE | models/vae | Where a separate VAE file goes |
| Generated images | output (mounted to ./output) | Where finished images are saved |
Final checklist
nvidia-smishows the GPU on the host- The NVIDIA Container Toolkit is installed so Docker can use the GPU
docker compose up -druns cleanly and the logs show the server uphttp://127.0.0.1:8188opens from the same machine- One checkpoint sits in
models/checkpointsand appears in Load Checkpoint - The first workflow queues with
Ctrl + Enterand its output lands in./output - The workflow is saved with
Ctrl + Sfor reuse
A node graph asks more of you than a single prompt box. In return, every decision — which model, which prompt, which sampler settings — becomes a node you can adjust, save, and repeat. Once one workflow behaves reliably, the work shifts from guessing to refining one node at a time.
What will your first workflow be once the install is done — a portrait, an illustration, or something else entirely? Tell us in the comments, and mention which node you are most curious about.
Read also: the earlier article, "Quick Trick: NVIDIA Container Toolkit + Docker GPU on a VPS", covers the Docker-side GPU prerequisites before you run any workload on top of them. Then you can continue to the companion article from the same batch at https://blog.rnevio.com/2026/10/how-to-install-piper-tts-on-docker-for.html.


Diskusi
Ada pertanyaan atau pengalaman yang ingin dibagikan?
Komentar ditinjau sebelum ditampilkan. Mari berdiskusi dengan sopan dan sesuai topik.
Tulis komentar