Skip to content

Commit

Permalink
chore: Enhance Docker compose setup for improved extension handling
Browse files Browse the repository at this point in the history
- Bind additional directories to the script folder in Docker Compose setup to fix extensions that don't respect the `--data-dir` rule.
- Add binding for a `ui-config.json` file in the Docker Compose configuration.

Signed-off-by: 陳鈞 <jim60105@gmail.com>
  • Loading branch information
jim60105 committed Mar 24, 2024
1 parent ae26534 commit b08dfa4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ services:
- /tmp
volumes:
- ./data:/data
# Bind the following to the script folder to fix some extensions that do not respect the --data-dir.
- ./data/config_states:/app/config_states
- ./data/extensions:/app/extensions
- ./data/models:/app/models
- ./data/ui-config.json:/app/ui-config.json
- cache:/.cache
- repositories:/app/repositories
deploy:
Expand Down

8 comments on commit b08dfa4

@yelban
Copy link

@yelban yelban commented on b08dfa4 Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a file? But after the container is started for the first time, the ui-config.json created in ./data/ is actually a folder~
Is this the reason for the error reported after starting the container below?

stable-diffusion-webui  |
100%|██████████| 3.97G/3.97G [01:17<00:00, 54.8MB/s]
stable-diffusion-webui  | loading settings: IsADirectoryError
stable-diffusion-webui  | Traceback (most recent call last):
stable-diffusion-webui  |   File "/app/modules/ui_loadsave.py", line 29, in __init__
stable-diffusion-webui  |     self.ui_settings = self.read_from_file()
stable-diffusion-webui  |   File "/app/modules/ui_loadsave.py", line 140, in read_from_file
stable-diffusion-webui  |     with open(self.filename, "r", encoding="utf8") as file:
stable-diffusion-webui  | IsADirectoryError: [Errno 21] Is a directory: '/data/ui-config.json'
stable-diffusion-webui  |

@jim60105
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this will definitely be a issue.
Docker will create a folder there when the source file does not exist (and will bind into the file if it exists).
So this modification will cause problems when running for the first time when sd-webui has not yet created files.
I'll think of another solution.

@yelban
Copy link

@yelban yelban commented on b08dfa4 Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your prompt response, and thank you even more for creating this Docker image that is much smaller than the mainstream auto1111. I have learned a lot from your build files. Please allow me to express my gratitude once again~
Regarding this issue, if we first create /app/ui-config.json in the Dockerfile, I wonder if there will be any other side effects?

...
RUN echo '{}' > /app/ui-config.json && \
    chown=$UID:0 /app/ui-config.json

ENTRYPOINT [ "dumb-init",...

@yelban
Copy link

@yelban yelban commented on b08dfa4 Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the parameter --data-dir /data will change the original paths of cache.json, extensions/, models/, scripts/, ui-config.json located under /app/ to the path /data. Perhaps the mounting path of the host machine can be divided into 2 layers.

sd-webui-data
├── configs
├── config_states
├── data
│   ├── cache.json
│   ├── extensions/
│   ├── models/
│   ├── scripts/
│   └── ui-config.json
└── repositories

Then change the mounted volume in docker-compose.yml to this.

volumes:
  - ./sd-webui-data/.cache:/.cache
  - ./sd-webui-data/data:/data
  - ./sd-webui-data/configs:/app/configs
  - ./sd-webui-data/config_states:/app/config_states
  - ./sd-webui-data/repositories:/app/repositories

It seems to be working fine now.

@jim60105
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad that someone likes it, that's why I enjoy working on open source projects.😄

I tested it and found that the empty JSON file works. Users will now receive one when cloning the git repository.
And I chose a different approach that does not automatically generate an empty directory.

Fixed this issue in 069a7b3.

@yelban
Copy link

@yelban yelban commented on b08dfa4 Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When starting up after pulling the latest version, Docker complains that it cannot find data/scripts and then exits abruptly.

image

@jim60105
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When starting up after pulling the latest version, Docker complains that it cannot find data/scripts and then exits abruptly.

image

Sorry for your inconvenience, it should be fixed now. ca0e5ca
Please pull the new image after the CI process completed or build it locally.

@yelban
Copy link

@yelban yelban commented on b08dfa4 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ca0e5c is now running smoothly, thank you for your prompt fix. The image built by your Dockerfile is much smaller than other machine learning images, which is really awesome!

The following two user experiences may help new users save some time.

  1. UID is set to 1001. The default starting UID for users created in Ubuntu 22.04 is 1000. When using this account to start docker compose, permission errors may occur.
    If UID 1001 does not exist on the host machine. ARG UID=1001 in Dockerfile, user: "1001:0" in docker-compose.yml needs corresponding modifications.
  2. After the first run of the stable-diffusion-webui, it will populate the content of ./data/ui-config.json. The version started by "dokcer compose" needs to manually save the configuration values in the UI interface before filling in the ui-config.json content.

Please sign in to comment.