-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docker files #1418
Add docker files #1418
Changes from 43 commits
97769de
ef5da9d
5b30983
5b30804
79ba09c
992979b
14b1acd
b68807b
45b1bdd
3af1528
ca45144
3cd3c7e
40e716b
8072641
c07de3d
854a4fd
ad9fc1e
81a45ed
ac5af9f
c37f540
17e9811
e5cc831
70a8626
19aa714
b5ccc63
416448b
1b094f3
d79de68
6d9d2b3
b05be6f
97f27c1
2c42a3e
97ac2e3
8b5b1b9
7c75e49
509a61b
66ec479
dfa4da0
b1ea926
6da2903
b32bcde
34d7617
4da6c44
ab528e1
e838927
b48ff50
6a5b5dc
6fb8f5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Docker | ||
|
||
on: | ||
push: | ||
branches-ignore: [ "*" ] | ||
# Publish semver tags as releases. | ||
tags: [ '*' ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
# This is used to complete the identity challenge | ||
# with sigstore/fulcio when running outside of PRs. | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Fooocus version check | ||
id: vercheck-fooocus | ||
run: | | ||
sed -e "s/version *= *'\([0-9\.]*\)'/version=\1/p" \ | ||
-e d \ | ||
fooocus_version.py >> $GITHUB_OUTPUT | ||
shell: bash | ||
|
||
- name: Docker Fooocus meta | ||
id: meta-fooocus | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ github.repository_owner }}/fooocus | ||
tags: | | ||
type=semver,pattern={{version}},value=${{ steps.vercheck-fooocus.outputs.version }} | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta-fooocus.outputs.tags }} | ||
labels: ${{ steps.meta-fooocus.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM nvidia/cuda:12.3.1-base-ubuntu22.04 | ||
ENV DEBIAN_FRONTEND noninteractive | ||
ENV CMDARGS --listen | ||
|
||
RUN apt-get update -y && \ | ||
apt-get install -y curl libgl1 libglib2.0-0 python3-pip python-is-python3 git && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY requirements_docker.txt requirements_versions.txt /tmp/ | ||
RUN pip install --no-cache-dir -r /tmp/requirements_docker.txt -r /tmp/requirements_versions.txt && \ | ||
rm -f /tmp/requirements_docker.txt /tmp/requirements_versions.txt | ||
RUN curl -fsL -o /usr/local/lib/python3.10/dist-packages/gradio/frpc_linux_amd64_v0.2 https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_amd64 && \ | ||
chmod +x /usr/local/lib/python3.10/dist-packages/gradio/frpc_linux_amd64_v0.2 | ||
|
||
RUN adduser --disabled-password --gecos '' user && \ | ||
mkdir -p /content/app /content/data | ||
|
||
COPY entrypoint.sh /content/ | ||
RUN chown -R user:user /content | ||
|
||
WORKDIR /content | ||
USER user | ||
|
||
RUN git clone https://github.com/whitehara/Fooocus /content/app | ||
RUN mv /content/app/models /content/app/models.org | ||
|
||
CMD [ "sh", "-c", "/content/entrypoint.sh ${CMDARGS}" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: '3.9' | ||
|
||
volumes: | ||
fooocus-data: | ||
|
||
services: | ||
app: | ||
build: . | ||
image: whitehara/fooocus | ||
ports: | ||
- 7865:7865 | ||
environment: | ||
- CMDARGS=--listen # 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: | ||
- fooocus-data:/content/data | ||
#- ./models:/import/models # Once you import files, you don't need to mount again. | ||
#- ./outputs:/import/outputs # Once you import files, you don't need to mount again. | ||
tty: true | ||
deploy: | ||
resources: | ||
reservations: | ||
devices: | ||
- driver: nvidia | ||
device_ids: ['0'] | ||
capabilities: [compute, utility] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Fooocus on Docker | ||
|
||
It's based on NVIDIA CUDA 12.3. See [Dockerfile](Dockerfile) for details. | ||
|
||
PyTorch version is 2.1. See [requirements_docker.txt](requirements_docker.txt) for details. | ||
|
||
## Quick start | ||
|
||
**This is just an easy way for testing. Please also see [Notes](#notes) for using.** | ||
|
||
Clone git, Then run the docker container `docker compose up --build` | ||
It takes a time to build the container image. | ||
When you see a messeage `Use the app with http://localhost:7865/` in the console message, you can access the URL on your browser. | ||
|
||
Your models, outputs are stored into 'fooocus-data' volume which may be stored in '/var/lib/docker/volumes'. | ||
|
||
## Use pre-built image | ||
|
||
The pre-built image is provided at `whitehara/fooocus` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could even automate the pipeline for each main branch update (or directly optimise thr process and use Gitlab releases for that...) and tag it with the corresponding version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If someone creates an official dockerhub account, I can modify the document for that. Then, I will stop providing my images in my dockerhub account. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm doing it in my repo. Please refer my Github Actions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the drive-by comment. I hadn't noticed you were already publishing the images to dockerhub. That makes sense. It wasn't my intention to suggest adding publishing images for this repo in this PR. Although that would be great! I was just getting impatient 🤭. Thanks for your work! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lllyasviel would you be willing to create a Dockerhub repository for Fooocus or shall i set it up + add the according actions to Github pushes (main) and/or releases? |
||
|
||
You can modify 'docker-compose.yml', then `docker compose up` | ||
|
||
Note: when you use the pre-built image, you need to make the 'fooocus-data' volume which permission is '777' ( all users can read/write.) before you run the container. | ||
Otherwise, you will see the permission error. | ||
|
||
## Details | ||
|
||
### Update the container manually | ||
|
||
When you are using `docker compose up --build` continuously, the container is not updated to the newest version of Fooocus automatically. | ||
If you want to use the newest one, you need to run `git pull` before you run `docker compose up --build` | ||
|
||
### Import models, outputs | ||
If you want to import files from models, outputs folder, you can uncomment following settings in docker-compose.yml | ||
``` | ||
#- ./models:/import/models # Once you import files, you don't need to mount again. | ||
#- ./outputs:/import/outputs # Once you import files, you don't need to mount again. | ||
``` | ||
Then run `docker compose up --build`, your files will be copied into /content/data/models, /content/data/outputs | ||
Since /content/data is a persistent volume folder, your files will be there when you re-run 'docker compose up --build` without above volume settings. | ||
|
||
|
||
### Paths inside the container | ||
|
||
|Path|Details| | ||
|-|-| | ||
|/content/app|The application stored folder| | ||
|/content/app/models.org|Original 'models' folder.<br> Files are copied to the '/content/app/models' which is symlinked to '/content/data/models' every time the container boots. (Existing files will not be overwritten.) | | ||
|/content/data|Persistent volume mount point| | ||
|/content/data/models|The folder is symlinked to '/content/app/models'| | ||
|/content/data/outputs|The folder is symlinked to '/content/app/outputs'| | ||
|
||
### Environments | ||
|
||
You can change 'config.txt' parameters by using environments. | ||
**The priority of using the environments is higher than the values defined in 'config.txt'. And they will be saved to the 'config_modification_tuorial.txt'** | ||
|
||
Docker specified environments are there. They are used by 'entrypoint.sh' | ||
|Environment|Details| | ||
|-|-| | ||
|DATADIR|'/content/data' location.| | ||
|CMDARGS|Arguments for [entry_with_update.py](entry_with_update.py) which is called by [entrypoint.sh](entrypoint.sh)| | ||
|config_path|'config.txt' location| | ||
|config_example_path|'config_modification_tutorial.txt' location| | ||
|
||
You can also use the same json key names and values explained in the 'config_modification_tutorial.txt' as the environments. | ||
See samples in the [docker-compose.yml](docker-compose.yml) | ||
|
||
## Notes | ||
|
||
- Please keep 'path_outputs' under '/content/app'. Otherwise, you will see an error when you open the history log. | ||
- Docker on Mac/Windows has a slow volume access problem when you use "bind mount" volume. When you see this problem, don't use "bind mount". Please refer to [this article](https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose) for not using "bind mount". |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
ORIGINALDIR=/content/app | ||
# Use predefined DATADIR if it is defined | ||
[[ x"${DATADIR}" == "x" ]] && DATADIR=/content/data | ||
|
||
# Make persistent dir from original dir | ||
function mklink () { | ||
mkdir -p $DATADIR/$1 | ||
ln -s $DATADIR/$1 $ORIGINALDIR | ||
} | ||
|
||
# Copy old files from import dir | ||
function import () { | ||
(test -d /import/$1 && cd /import/$1 && cp -Rpn . $DATADIR/$1/) | ||
} | ||
|
||
cd $ORIGINALDIR | ||
|
||
# models | ||
mklink models | ||
# Copy original files | ||
(cd $ORIGINALDIR/models.org && cp -Rpn . $ORIGINALDIR/models/) | ||
# Import old files | ||
import models | ||
|
||
# outputs | ||
mklink outputs | ||
# Import old files | ||
import outputs | ||
|
||
# Start application | ||
python launch.py $* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
torch==2.2.0 | ||
torchvision==0.17.0 | ||
torchaudio==2.2.0 | ||
torchtext==0.17.0 | ||
torchdata==0.7.1 | ||
xformers==0.0.24 | ||
triton==2.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest changing the image name to something more generic. Maybe plainly
fooocus
?