TrainReq / Dockerfile
yildizcep's picture
Upload Dockerfile
1ee3188
# Stage 1: Base
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 as base
ARG WEBUI_VERSION=v1.7.0
ARG DREAMBOOTH_COMMIT=cf086c536b141fc522ff11f6cffc8b7b12da04b9
ARG KOHYA_VERSION=v22.3.1
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Europe/London \
PYTHONUNBUFFERED=1 \
SHELL=/bin/bash
# Create workspace working directory
WORKDIR /
# Install Ubuntu packages
RUN apt update && \
apt -y upgrade && \
apt install -y --no-install-recommends \
build-essential \
software-properties-common \
python3.10-venv \
python3-pip \
python3-tk \
python3-dev \
nodejs \
npm \
bash \
dos2unix \
git \
git-lfs \
ncdu \
nginx \
net-tools \
inetutils-ping \
openssh-server \
libglib2.0-0 \
libsm6 \
libgl1 \
libxrender1 \
libxext6 \
ffmpeg \
wget \
curl \
psmisc \
rsync \
vim \
zip \
unzip \
p7zip-full \
htop \
pkg-config \
plocate \
libcairo2-dev \
libgoogle-perftools4 \
libtcmalloc-minimal4 \
apt-transport-https \
ca-certificates && \
update-ca-certificates && \
apt clean && \
rm -rf /var/lib/apt/lists/* && \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
# Set Python
RUN ln -s /usr/bin/python3.10 /usr/bin/python
# Install Torch, xformers and tensorrt
RUN pip3 install --no-cache-dir torch==2.0.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 && \
pip3 install --no-cache-dir xformers==0.0.22 tensorrt
# Stage 2: Install applications
FROM base as setup
RUN mkdir -p /sd-models
# Add SDXL models and VAE
# These need to already have been downloaded:
# wget https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors
# wget https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors
# wget https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors
COPY famousai-v2.safetensors /sd-models/sd_xl_base_1.0.safetensors
COPY sd_xl_refiner_1.0.safetensors /sd-models/sd_xl_refiner_1.0.safetensors
COPY sdxl_vae.safetensors /sd-models/sdxl_vae.safetensors
COPY woman_5200_imgs_1024x1024.zip /sd-models/woman_5200_imgs_1024x1024.zip
COPY man_5200_imgs_1024x1024.zip /sd-models/man_5200_imgs_1024x1024.zip
COPY 24GB_TextEncoder.json /sd-models/24GB_TextEncoder.json
COPY 48GB_TextEncoder.json /sd-models/48GB_TextEncoder.json
RUN unzip /sd-models/man_5200_imgs_1024x1024.zip -d /sd-models/man && \
unzip /sd-models/woman_5200_imgs_1024x1024.zip -d /sd-models/woman && \
rm /sd-models/man_5200_imgs_1024x1024.zip && \
rm /sd-models/woman_5200_imgs_1024x1024.zip
# Clone the git repo of the Stable Diffusion Web UI by Automatic1111
# and set version
WORKDIR /
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \
cd /stable-diffusion-webui && \
git checkout tags/${WEBUI_VERSION}
WORKDIR /stable-diffusion-webui
RUN python3 -m venv --system-site-packages /venv && \
source /venv/bin/activate && \
pip3 install --no-cache-dir torch==2.0.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 && \
pip3 install --no-cache-dir xformers && \
deactivate
# Install the dependencies for the Automatic1111 Stable Diffusion Web UI
COPY a1111/requirements.txt a1111/requirements_versions.txt ./
COPY a1111/cache-sd-model.py a1111/install-automatic.py ./
RUN source /venv/bin/activate && \
python3 -m install-automatic --skip-torch-cuda-test && \
deactivate
# Cache the Stable Diffusion Models
# SDXL models result in OOM kills with 8GB system memory, probably need 12GB+ to cache these
RUN source /venv/bin/activate && \
python3 cache-sd-model.py --no-half-vae --use-cpu=all --ckpt /sd-models/sd_xl_base_1.0.safetensors && \
python3 cache-sd-model.py --no-half-vae --use-cpu=all --ckpt /sd-models/sd_xl_refiner_1.0.safetensors && \
deactivate
# Clone the Automatic1111 Extensions
RUN git clone https://github.com/d8ahazard/sd_dreambooth_extension.git extensions/sd_dreambooth_extension && \
git clone --depth=1 https://github.com/deforum-art/sd-webui-deforum.git extensions/deforum && \
git clone --depth=1 https://github.com/Mikubill/sd-webui-controlnet.git extensions/sd-webui-controlnet && \
git clone --depth=1 https://github.com/ashleykleynhans/a1111-sd-webui-locon.git extensions/a1111-sd-webui-locon && \
git clone --depth=1 https://github.com/Gourieff/sd-webui-reactor.git extensions/sd-webui-reactor && \
git clone --depth=1 https://github.com/zanllp/sd-webui-infinite-image-browsing.git extensions/infinite-image-browsing && \
git clone --depth=1 https://github.com/Uminosachi/sd-webui-inpaint-anything.git extensions/inpaint-anything && \
git clone --depth=1 https://github.com/Bing-su/adetailer.git extensions/adetailer && \
git clone --depth=1 https://github.com/civitai/sd_civitai_extension.git extensions/sd_civitai_extension && \
git clone --depth=1 https://github.com/BlafKing/sd-civitai-browser-plus.git extensions/sd-civitai-browser-plus
# Install dependencies for Deforum, ControlNet, ReActor, Infinite Image Browsing,
# After Detailer, and CivitAI Browser+ extensions
RUN source /venv/bin/activate && \
cd /stable-diffusion-webui/extensions/deforum && \
pip3 install -r requirements.txt && \
cd /stable-diffusion-webui/extensions/sd-webui-controlnet && \
pip3 install -r requirements.txt && \
cd /stable-diffusion-webui/extensions/sd-webui-reactor && \
pip3 install -r requirements.txt && \
pip3 install onnxruntime-gpu && \
cd /stable-diffusion-webui/extensions/infinite-image-browsing && \
pip3 install -r requirements.txt && \
cd /stable-diffusion-webui/extensions/adetailer && \
python3 -m install && \
cd /stable-diffusion-webui/extensions/sd_civitai_extension && \
pip3 install -r requirements.txt && \
deactivate
# Install dependencies for inpaint anything extension
RUN source /venv/bin/activate && \
pip3 install segment_anything lama_cleaner && \
deactivate
# Install dependencies for Civitai Browser+ extension
RUN source /venv/bin/activate && \
cd /stable-diffusion-webui/extensions/sd-civitai-browser-plus && \
pip3 install send2trash ZipUnicode fake-useragent && \
deactivate
# Set Dreambooth extension version
WORKDIR /stable-diffusion-webui/extensions/sd_dreambooth_extension
RUN git checkout main && \
git reset ${DREAMBOOTH_COMMIT} --hard
# Install the dependencies for the Dreambooth extension
WORKDIR /stable-diffusion-webui
COPY a1111/requirements_dreambooth.txt ./requirements.txt
RUN source /venv/bin/activate && \
cd /stable-diffusion-webui/extensions/sd_dreambooth_extension && \
pip3 install -r requirements.txt && \
deactivate
# Add inswapper model for the ReActor extension
RUN mkdir -p /stable-diffusion-webui/models/insightface && \
cd /stable-diffusion-webui/models/insightface && \
wget https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx
# Configure ReActor to use the GPU instead of the CPU
RUN echo "CUDA" > /stable-diffusion-webui/extensions/sd-webui-reactor/last_device.txt
# Fix Tensorboard
RUN source /venv/bin/activate && \
pip3 uninstall -y tensorboard tb-nightly && \
pip3 install tensorboard tensorflow && \
pip3 cache purge && \
deactivate
# Install Kohya_ss
RUN git clone https://github.com/bmaltais/kohya_ss.git /kohya_ss
WORKDIR /kohya_ss
COPY kohya_ss/requirements* ./
RUN git checkout ${KOHYA_VERSION} && \
python3 -m venv --system-site-packages venv && \
source venv/bin/activate && \
pip3 install --no-cache-dir torch==2.0.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 && \
pip3 install --no-cache-dir xformers==0.0.22 \
bitsandbytes==0.41.1 \
tensorboard==2.14.1 \
tensorflow==2.14.0 \
wheel \
scipy \
tensorrt && \
pip3 install -r requirements.txt && \
pip3 install . && \
pip3 cache purge && \
deactivate
# Install ComfyUI
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /ComfyUI
WORKDIR /ComfyUI
RUN python3 -m venv --system-site-packages venv && \
source venv/bin/activate && \
pip3 install --no-cache-dir torch==2.0.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 && \
pip3 install --no-cache-dir xformers==0.0.22 && \
pip3 install -r requirements.txt && \
deactivate
# Install ComfyUI Custom Nodes
RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git custom_nodes/ComfyUI-Manager && \
cd custom_nodes/ComfyUI-Manager && \
source /ComfyUI/venv/bin/activate && \
pip3 install -r requirements.txt && \
pip3 cache purge && \
deactivate
# Install Application Manager
WORKDIR /
RUN git clone https://github.com/ashleykleynhans/app-manager.git /app-manager && \
cd /app-manager && \
npm install
# Install Jupyter
WORKDIR /
RUN pip3 install -U --no-cache-dir jupyterlab \
jupyterlab_widgets \
ipykernel \
ipywidgets \
gdown
# Install rclone
RUN curl https://rclone.org/install.sh | bash
# Install runpodctl
RUN wget https://github.com/runpod/runpodctl/releases/download/v1.10.0/runpodctl-linux-amd -O runpodctl && \
chmod a+x runpodctl && \
mv runpodctl /usr/local/bin
# Install croc
RUN curl https://getcroc.schollz.com | bash
# Install speedtest CLI
RUN curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash && \
apt install speedtest
# Install CivitAI Model Downloader
RUN git clone --depth=1 https://github.com/ashleykleynhans/civitai-downloader.git && \
mv civitai-downloader/download.sh /usr/local/bin/download-model && \
chmod +x /usr/local/bin/download-model
# Copy Stable Diffusion Web UI config files
COPY a1111/relauncher.py a1111/webui-user.sh a1111/config.json a1111/ui-config.json /stable-diffusion-webui/
# ADD SDXL styles.csv
ADD https://raw.githubusercontent.com/Douleb/SDXL-750-Styles-GPT4-/main/styles.csv /stable-diffusion-webui/styles.csv
# Copy ComfyUI Extra Model Paths (to share models with A1111)
COPY comfyui/extra_model_paths.yaml /ComfyUI/
# Remove existing SSH host keys
RUN rm -f /etc/ssh/ssh_host_*
# NGINX Proxy
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/502.html /usr/share/nginx/html/502.html
COPY nginx/README.md /usr/share/nginx/html/README.md
WORKDIR /
# Copy the scripts
COPY --chmod=755 scripts/* ./
# Copy the accelerate configuration
COPY kohya_ss/accelerate.yaml ./
# Start the container
SHELL ["/bin/bash", "--login", "-c"]
ENTRYPOINT [ "/start.sh" ]