Sign inSign up

cocytuselias2023/stable-diffusion-webui

By cocytuselias2023

•Updated over 3 years ago

Repository: https://github.com/AUTOMATIC1111/stable-diffusion-webui

Image
3

362

cocytuselias2023/stable-diffusion-webui repository overview

⁠Building and Running the Docker Image for stable-diffusion-webui

⁠Docker Build

stable-diffusion-webui is an integrated environment based on stable-diffusion, including a WebUI that can be accessed by a browser, an API, etc.

First, we need to build the docker image for stable-diffusion-webui. Because stable-diffusion is a stable diffusion drawing model, it requires support on the GPU.

Secondly, stable-diffusion-webui is recommended to run on the operating system of ubuntu 20.04.

During the installation process, there are some support issues to be aware of:

  • Support for python 3.10.6 is required. Otherwise, you may encounter a RuntimeError: Couldn't Install Torch when executing /bin/bash webui.sh. Related Issue⁠.
  • cuda and GPU support are required. Therefore, the base image uses nvidia/cuda, and you need to choose the corresponding tag based on the CUDA version on the physical machine. For example, if I choose CUDA11.4.1/Driver470.82.01/CUDNN8.2.4 on Alibaba Cloud, then my base image should choose nvidia/cuda:11.4.1-base-ubuntu20.04.
  • You need to install ffmpeg libsm6 libxext6 , otherwise it will report ImportError: libGL.so.1: cannot open shared object file: No such file or directory. Stackoverflow Answer⁠.
  • You need to install libbz2-dev liblzma-dev, otherwise it will report No module named '_lzma'.
  • You need to set export COMMANDLINE_ARGS="--skip-torch-cuda-test" in webui-user.sh, otherwise it will not pass the GPU test.
  • You need to run webui.sh with a non-root user. Remember to grant permission to the project directory before running it with a non-root user.
  • Because the installation and execution are integrated in webui.sh, it may get stuck at the end if you start webui.sh directly. Therefore, you need to add --exit parameter when running webui.sh. Meaning of Parameters⁠.
  • When building the docker image, a large number of overseas resources will be downloaded, so it is best to do it on an overseas server.

Here is an example of a build file:

FROM nvidia/cuda:11.6.0-base-ubuntu20.04 AS builder

WORKDIR /

ENV TZ=Asia/Shanghai \
    DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y wget git bzip2 ca-certificates curl python3 python3-venv numactl libjemalloc-dev make automake gcc g++ subversion build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev liblzma-dev ffmpeg libsm6 libxext6 && \
    git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && cd stable-diffusion-webui && echo "export COMMANDLINE_ARGS=\"--skip-torch-cuda-test\"" >> webui-user.sh && \
    wget https://static.elias.ink/python/3/Python-3.10.6.tgz && tar -zvxf Python-3.10.6.tgz && cd Python-3.10.6/ && ./configure --enable-optimizations && make && make install && ln -s /usr/local/bin/python3.10 /usr/bin/python && \
    useradd -m -s /bin/bash diffusion && echo "diffusion:yupoo" | chpasswd && \
    chown -R diffusion /stable-diffusion-webui/

USER diffusion

WORKDIR /stable-diffusion-webui

RUN /bin/bash webui.sh --exit

CMD ["/bin/bash"]

To run the image, simply execute docker build -t ${your_image_name}:${you_image_tag} and wait patiently for the compilation to complete.

image-20230317212943943

If Exiting because of --exit argument appears, it means the installation is complete. Just wait a moment.

⁠Basic Environment Setup

Next, the physical machine needs to be configured to support the operation of the image.

First, we need version docker 19.03 or higher. Installation tutorials can be found in the official documentation⁠.

After installation, NVIDIA's CUDA and related GPU drivers need to be installed. Here, I used Aliyun's server, which has automatically installed the drivers for me. If the driver installation is successful, running nvidia-smi will yield the following output.

image-20230317215337848

After the above steps are completed, nvidia-docker needs to be installed to enable the container to use GPU resources.

I will use two mainstream operating systems as examples to demonstrate how to install nvidia-docker.

⁠Ubuntu 20.02 Installation of nvidia-docker

Add the tool package's package storage repository to the system:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
  && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
  && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

Install nvidia-docker2.

apt-get update && apt-get install -y nvidia-docker2
⁠CentOS 7 Installation of nvidia-docker

Add the tool package's package storage repository to the system:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo

Install nvidia-container-toolkit and nvidia-docker2.

sudo yum install -y nvidia-container-toolkit nvidia-docker2

⁠Post-Installation Verification

After installation is complete, the docker process needs to be restarted. Regardless of whether it is Centos or Ubuntu, execute the following command:

sudo systemctl restart docker

Afterwards, run a test image to check if everything is working properly.

docker run -it --gpus all nvidia/cuda:11.4.0-base-ubuntu20.04 nvidia-smi

Executing the above command will output the following content:

image-20230317215859283

Then, run the stable-diffusion-webui image:

docker run -it --gpus all cocytuselias2023/stable-diffusion-webui:cuda11.4.1-ubuntu20.04 /bin/bash webui.sh --share --no-half --enable-insecure-extension-access --xformers --gradio-queue

The above command runs in the foreground.

docker run --gpus all cocytuselias2023/stable-diffusion-webui:cuda11.4.1-ubuntu20.04 /bin/bash webui.sh --share --no-half --enable-insecure-extension-access --xformers --gradio-queue

The above command runs in the background.

After starting, a safetensors file with a size of 3.97G will be downloaded.

image-20230317212731012

Once the download is complete, you will be given a Public URL. This address can be used on your server as long as it can access the Internet, even if it is not on the public network. Mine is https://2bf2bdf1-6d8f-46c2.gradio.live.

image-20230317213515640

Then you can enjoy playing around.

image-20230317220934345

Generate a dog.

image-20230317221752755

Here is the Chinese version: https://blacksmith.elias.ink/archives/docker-bian-yi-bing-yun-xing-stable-diffusion-webui-jing-xiang⁠

By the way, I used ChatGPT to translate the Chinese version into English.

Tag summary

Content type

Image

Digest

sha256:343c24eea…

Size

5.3 GB

Last updated

over 3 years ago

docker pull cocytuselias2023/stable-diffusion-webui:cuda12.1.0-ubuntu20.04