Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ability to build and run cpu-only-fooocus docker image locally only with cpu #3877

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cpu-only-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
cpu-only-fooocus:
user: "${UID}:${GID}" # Run as the same user as the host
build:
context: . # Use the Dockerfile in the current directory
dockerfile: Dockerfile # Custom Dockerfile (if needed)
container_name: cpu-only-fooocus
ports:
- "7865:7865"
environment:
- CMDARGS=--listen --always-cpu --preset realistic # Arguments for launch.py.
- DATADIR=/content/data # Directory which stores models, outputs dir
- config_path=/content/data/config.txt
- config_example_path=/content/data/config_modification_tutorial.txt
- path_checkpoints=/content/data/models/checkpoints/
- path_loras=/content/data/models/loras/
- path_embeddings=/content/data/models/embeddings/
- path_vae_approx=/content/data/models/vae_approx/
- path_upscale_models=/content/data/models/upscale_models/
- path_inpaint=/content/data/models/inpaint/
- path_controlnet=/content/data/models/controlnet/
- path_clip_vision=/content/data/models/clip_vision/
- path_fooocus_expansion=/content/data/models/prompt_expansion/fooocus_expansion/
- path_outputs=/content/app/outputs/ # Warning: If it is not located under '/content/app', you can't see history log!
volumes:
- ~/.cpu-only-fooocus:/content/data
- ~/.cpu-only-fooocus/models:/import/models
- ~/.cpu-only-fooocus/outputs:/import/outputs
tty: true

56 changes: 56 additions & 0 deletions cpu-only-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# CPU-Only Fooocus Docker Setup

## Overview
This guide explains how to run Fooocus inside a Docker container using only the CPU, without utilizing a GPU.

## Prerequisites
Ensure you have the following installed on your system:
- Docker
- Docker Compose
- Bash shell (for executing the script)

## Running the Docker Container
To start the container, run the following command:
```sh
./cpu-only-runner.sh
```
This script will:
- Create necessary directories for mounting volumes.
- Check if a container named `cpu-only-fooocus` already exists.
- If it exists, it will prompt whether to rebuild the container.
- If it does not exist, it will create and start a new one using `docker-compose`.

## Accessing the UI
Once the container is running, access the Fooocus UI by opening the following URL in your browser:
```
http://localhost:7865/
```

## Viewing Logs
To follow the logs of the running container, use:
```sh
docker logs cpu-only-fooocus --follow
```

## Stopping the Container
To stop the running container, execute:
```sh
docker stop cpu-only-fooocus
```

## Configuration Details
The container uses `cpu-only-docker-compose.yml`, which:
- Runs the container with CPU-only mode using the `CMDARGS=--listen --always-cpu --preset realistic` environment variable.
- Mounts directories from `~/.cpu-only-fooocus` to store models and outputs.
- Exposes port `7865` for accessing the UI.

For further modifications, update `cpu-only-docker-compose.yml` or `cpu-only-runner.sh` accordingly.

## Troubleshooting
- Ensure Docker and Docker Compose are installed and running.
- If the container does not start properly, check the logs using `docker logs cpu-only-fooocus`.
- If you encounter permission issues, try running the script with `sudo`.

Enjoy using Fooocus with CPU-only mode!


33 changes: 33 additions & 0 deletions cpu-only-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Define variables
CPU_ONLY_FOOCUS_HOME="$HOME/.cpu-only-fooocus"
CPU_ONLY_FOOCUS_TMP="$CPU_ONLY_FOOCUS_HOME/tmp"
CPU_ONLY_FOOCUS_MODULES="$CPU_ONLY_FOOCUS_HOME/modules"
CPU_ONLY_FOOCUS_OUTPUTS="$CPU_ONLY_FOOCUS_HOME/outputs"
CPU_ONLY_CONTAINER_NAME="cpu-only-fooocus"

# Create mount volumes
mkdir -pv "$CPU_ONLY_FOOCUS_TMP"
mkdir -pv "$CPU_ONLY_FOOCUS_MODULES"
mkdir -pv "$CPU_ONLY_FOOCUS_OUTPUTS"

# Check if the container is running
if docker ps -a --format '{{.Names}}' | grep -q "^${CPU_ONLY_CONTAINER_NAME}$"; then
echo "Container '${CPU_ONLY_CONTAINER_NAME}' already exists."
read -p "Do you want to rebuild the image? (y/N): " rebuild_choice
if [[ "$rebuild_choice" =~ ^[Yy]$ ]]; then
echo "Stopping and removing existing container..."
docker stop "${CPU_ONLY_CONTAINER_NAME}"
docker rm "${CPU_ONLY_CONTAINER_NAME}"
echo "Rebuilding the Docker image..."
docker-compose -f cpu-only-docker-compose.yml up --build -d
else
echo "Starting existing container..."
docker start "${CPU_ONLY_CONTAINER_NAME}"
fi
else
echo "Starting a new container..."
docker-compose -f cpu-only-docker-compose.yml up -d
fi