Skip to content

Instantly share code, notes, and snippets.

@xenogenesi
Last active February 19, 2025 16:13
Show Gist options
  • Save xenogenesi/e62d3d13dadbc164124c830e9c453668 to your computer and use it in GitHub Desktop.
Save xenogenesi/e62d3d13dadbc164124c830e9c453668 to your computer and use it in GitHub Desktop.
Docker file for Wav2Lip
# Ignore everything
**
# Allow files and directories
!/audio.py
!/Dockerfile
!/hparams.py
!/preprocess.py
!/checkpoints/
!/evaluation/
!/hq_wav2lip_train.py
!/README.md
!/temp/
!/color_syncnet_train.py
!/face_detection/
!/inference.py
!/requirements.txt
!/filelists/
!/models/
!/results/
!/wav2lip_train.py
# Ignore unnecessary files inside allowed directories
# This should go after the allowed directories
**/*~
**/*.log
**/.DS_Store
**/Thumbs.db
# 1. install a version of docker with gpu support (docker-ce >= 19.03)
# 2. enter the project directory and build the wav2lip image:
# docker build -t wav2lip .
# 3. allow root user to connect to the display
# xhost +local:root
# 4. instantiate the container
# docker run --rm --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix -v $PWD:/workspace/src -e DISPLAY=$DISPLAY --device /dev/dri -ti wav2lip bash
# NOTES:
# export CUDA_VISIBLE_DEVICES="" ## force cpu only
# Based on https://github.com/1adrianb/face-alignment/blob/master/Dockerfile
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
RUN export DEBIAN_FRONTEND=noninteractive RUNLEVEL=1 ; \
apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake git curl ca-certificates \
vim \
python3-pip python3-dev python3-wheel \
libglib2.0-0 libxrender1 python3-soundfile \
ffmpeg && \
rm -rf /var/lib/apt/lists/* && \
pip3 install --upgrade setuptools
# RUN curl -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
# chmod +x ~/miniconda.sh && \
# ~/miniconda.sh -b -p /opt/conda && \
# rm ~/miniconda.sh
# ENV PATH /opt/conda/bin:$PATH
# RUN conda config --set always_yes yes --set changeps1 no && conda update -q conda
# RUN conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
# # Install Wav2Lip package
# # NOTE we use the git clone to install the requirements only once
# # (if we use COPY it will invalidate the cache and reinstall the dependencies for every change in the sources)
WORKDIR /workspace
RUN chmod -R a+w /workspace
RUN git clone https://github.com/Rudrabha/Wav2Lip
WORKDIR /workspace/Wav2Lip
RUN pip3 install -r requirements.txt
RUN mkdir -p /root/.cache/torch/checkpoints && \
curl -SL -o /root/.cache/torch/checkpoints/s3fd-619a316812.pth "https://www.adrianbulat.com/downloads/python-fan/s3fd-619a316812.pth"
# !!! NOTE !!! nvidia-driver version must match the version installed on the host(/docker server)
RUN export DEBIAN_FRONTEND=noninteractive RUNLEVEL=1 ; \
apt-get update && apt-get install -y --no-install-recommends \
nvidia-driver-450 mesa-utils && \
rm -rf /var/lib/apt/lists/*
# create the working directory, to be mounted with the bind option
RUN mkdir /workspace/src
WORKDIR /workspace/src
@michaelharmonart
Copy link

After installing and running everything when I run "docker run --rm --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix -v $PWD:/workspace/src -e DISPLAY=$DISPLAY --device /dev/dri -ti wav2lip bash" it returns "docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]." Do you know what the problem might be?

@xenogenesi
Copy link
Author

Sorry I never seen that error, maybe a version problem? Are you using a docker-ce >= 19.03?

docker-ce                  5:20.10.3~3-0~debian-buster
docker-ce-cli              5:20.10.3~3-0~debian-buster
docker-ce-rootless-extras  5:20.10.3~3-0~debian-buster

@michaelharmonart
Copy link

Yep when I run "docker version" it says I'm on docker community edition v 20.10.3

I'm on Ubuntu by the way (Well, actually Kubuntu, but it shouldn't make a difference)

@xenogenesi
Copy link
Author

It's been a few months since I tried it and it worked, in the meantime a few versions of the various nvidia components have been updated (I use debian/sid) and now I have some problems to make it work too, but it gives me a different error.

@michaelharmonart
Copy link

Well, just due to time constraints I ended up installing it normally, without docker to do my tests. So there's no urgency for it to be fixed, but I wish you good luck!

@johde
Copy link

johde commented May 6, 2021

I had to add RUN pip3 install --upgrade pip to the docker file just before RUN pip3 install -r requirements.txt to get it to install the requirements correctly.

@iamkhalidbashir
Copy link

I had to add RUN pip3 install --upgrade pip to the docker file just before RUN pip3 install -r requirements.txt to get it to install the requirements correctly.

This is important

@wangxingchao
Copy link

Exactly this works for me.

Why doesnot anyone had already created the docker image share to public repo?

@xenogenesi
Copy link
Author

Why doesnot anyone had already created the docker image share to public repo?

I haven't used this image for a while, lately when I need some python-ML projects I just use Conda.

@chrisbward
Copy link

I had to add RUN pip3 install --upgrade pip to the docker file just before RUN pip3 install -r requirements.txt to get it to install the requirements correctly.

This is important

Super important, was fun wasting time today

@Vipinstack
Copy link

Screenshot from 2023-02-24 13-29-06

image

" Do you know what the problem might be?

@Drake4537
Copy link

I have been having problems running with this error python: can't open file
'inference.py': [Errno 2] No such file or directory

@cabraljv
Copy link

The base image FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04 seems to be deprecated. Any pre-built image ready to run available?

@rudolfKischer
Copy link

The base image FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04 seems to be deprecated. Any pre-built image ready to run available?

Did any find a resolution for this?

I am having some issues trying to use newer base images

@slopcop
Copy link

slopcop commented Dec 13, 2023

Having issues with the regular conda dev too. Maybe some dependency stuff?

@vido89
Copy link

vido89 commented Feb 17, 2025

Hi there!
Im on Mint 22.1 and Im facing with this error

Step 1/11 : FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
manifest for nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04 not found: manifest unknown: manifest unknown

So with which version should I replace cuda:10.1-cudnn7-devel-ubuntu18.04 in docker Im not familiar with it ?
Tnx

@xenogenesi
Copy link
Author

Hi there! Im on Mint 22.1 and Im facing with this error

Step 1/11 : FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
manifest for nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04 not found: manifest unknown: manifest unknown

So with which version should I replace cuda:10.1-cudnn7-devel-ubuntu18.04 in docker Im not familiar with it ? Tnx

It depends on several factors: the PC architecture and graphics card, the NVIDIA driver version. (I haven't used Docker with NVIDIA or Wav2Lip for a long time. I mainly use Conda, but I'm not sure if it works with Wav2Lip, I've never tried. Aside from giving you a couple of links I wouldn't know how to help you)

https://docs.nvidia.com/deeplearning/cudnn/backend/latest/reference/support-matrix.html
https://nvidia.github.io/container-wiki/toolkit/container-images.html
https://hub.docker.com/r/nvidia/cuda/

Good luck

@vido89
Copy link

vido89 commented Feb 17, 2025

Hi @xenogenesi tnx for quick reply I installed Docker CE (a.k.a Docker Engine) and finally got the sexy output:
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi

Mon Feb 17 15:18:49 2025       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.120                Driver Version: 550.120        CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce GTX 750 Ti      Off |   00000000:05:00.0  On |                  N/A |
| 34%   31C    P8              1W /   38W |     298MiB /   2048MiB |     12%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+

so when I run sudo docker build -t wav2lip . Im getting

RROR: failed to solve: nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04: failed to resolve source metadata for docker.io/nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04: docker.io/nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04: not found

@xenogenesi
Copy link
Author

xenogenesi commented Feb 17, 2025

Hi @vido89

so, your setup is:

gtx 750 ti
gpu arch: maxwell
CUDA (compute capability of the gpu): 5.0
installed driver: 550.120
cuda installed libs: 12.4

Looking at the matrix link I think you should be able to use you gpu, but I see only nvidia docker images for cuda libs >= 12.8, and I think you need to match that on your host (not sure). Once you got 12.8 on your system just change the link in the Dockerfile with one from the nvidia site (eg: 12.8.0-cudnn-devel-ubuntu24.04). I don't even know if you need the devel version, maybe the runtime is enough.

@xenogenesi
Copy link
Author

@vido89

nvidia also have some unsupported images, but the 12.4 need cudnn8 and I don't think you can get it working with your driver version (not sure about that either)

https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/unsupported-tags.md

@vido89
Copy link

vido89 commented Feb 17, 2025

Hi @xenogenesi OK tnx for the tip I updated cuda, but now Im facing this error

1816.1 ERROR: Cannot install -r requirements.txt (line 1), -r requirements.txt (line 4) and numpy==1.17.1 because these package versions have conflicting dependencies.
1816.1 
1816.1 The conflict is caused by:
1816.1     The user requested numpy==1.17.1
1816.1     librosa 0.7.0 depends on numpy>=1.15.0
1816.1     opencv-python 4.10.0.82 depends on numpy>=1.17.0; python_version >= "3.7"
1816.1     opencv-python 4.10.0.82 depends on numpy>=1.17.3; python_version >= "3.8"
1816.1 
1816.1 To fix this you could try to:
1816.1 1. loosen the range of package versions you've specified
1816.1 2. remove package versions to allow pip attempt to solve the dependency conflict
1816.1 
1816.1 ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
------
Dockerfile:46

@xenogenesi
Copy link
Author

xenogenesi commented Feb 17, 2025

@vido89

Have you seen/tried this?

I had to add RUN pip3 install --upgrade pip to the docker file just before RUN pip3 install -r requirements.txt to get it to install the requirements correctly

You may also need to change nvidia-driver-450 on line 54, not sure with what version, nvidia-driver only (the latest) or a specific version

@vido89
Copy link

vido89 commented Feb 17, 2025

@xenogenesi I saw that but I totally forgot about it tnx for pointing it out for me. Ok I added RUN pip3 install --upgrade pip before RUN pip3 install -r requirements.txt to docker file. And I replaced nvidia-driver-450 with nvidia-driver-550, how do I clear "chache" from docker work place Im uptating requirements.txt in /var/lib/docker/overlay2/l/VU7YL3WYJAON6BBFKDT3QKWZQZ/workspace/Wav2Lip/requirements.txt ? I did not add [pre-trained model] in to face_detection/detection/sfd/s3fd.pth ?
Edit: Now Im getting

ERROR: Could not find a version that satisfies the requirement opencv-python==4.1.2.30 (from versions: 3.4.0.14, 3.4.10.37, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.63, 3.4.18.65, 4.3.0.38, 4.4.0.40, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.60, 4.5.5.64, 4.6.0.66, 4.7.0.72, 4.8.0.74, 4.8.0.76, 4.8.1.78, 4.9.0.80, 4.10.0.82, 4.10.0.84, 4.11.0.86)
13.27 ERROR: No matching distribution found for opencv-python==4.1.2.30

@xenogenesi
Copy link
Author

xenogenesi commented Feb 17, 2025

@vido89
docker build should have an option to ignore the cache --no-cache.

ERROR: Could not find a version that satisfies the requirement opencv-python==4.1.2.30

I see two options but both annoying

  1. test and eventually fix (if needed) Wav2Lip to support 4.3.0.38 (the next nearest supported release, but being 4.1 -> 4.3 will have api compatibility breaks I guess)
  2. you could try to install some specific version of conda/python3 which supports that version of opencv-python (don't know if there's one nor how to check)

https://docs.anaconda.com/miniconda/install/#quick-command-line-install (see "To download an older version)
https://repo.anaconda.com/miniconda/

and then replace the line with Miniconda3-latest-Linux-x86_64.sh

@xenogenesi
Copy link
Author

xenogenesi commented Feb 17, 2025

@vido89 , I think you should try this one: Miniconda3-py38_23.11.0-2-Linux-x86_64.sh

python 3.8, miniconda 23.11.0-2 (3.6 and 3.7 should also support opencv-python==4.1.2.30)

@vido89
Copy link

vido89 commented Feb 18, 2025

@xenogenesi Ok so it should go like this

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-py38_23.11.0-2-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

After installing, close and reopen your terminal application or refresh it by running the following command:
source ~/miniconda3/bin/activate
then
conda init --all

But are you sure that I need Miniconda3-py38_23.11.0-2-Linux-x86_64.sh should that be py36 ?

Edit: I need
librosa==0.7.0
numpy==1.17.1
opencv-contrib-python>=4.2.0.34
opencv-python==4.1.0.25
torch==1.1.0
torchvision==0.3.0
tqdm==4.45.0
numba==0.48

Edit:2
How will docker "see" opencv-python==4.1.0.25 from conda ? Should I install conda "in side of docker" ?

@xenogenesi
Copy link
Author

@vido89 I suggested 3.8 because is the most recent version, but 3.6 and 3.7 should support the opencv package too.

You know, I didn't notice that the miniconda section is commented out, before proceeding with conda you might want to consider if miniconda is the best option to install and run python3.[6-8] on that nvidia/ubuntu docker image, might be there's some ppa? or build it from sources? install some prepackaged binary?

If you proceed using conda I think you can avoid to install python stuff with apt-get (python3-pip python3-dev python3-wheel python3-soundfile) but need to understand how to install the corresponding packages using pip in your Dockerfile after conda python3.x is installed and running,
the commented ENV line 34 should avoid the need for calling activate (I guess, never tested), also I don't think conda init --all is needed, only to initialize available shells

line 36 conda commands looks useful too, to config the installed conda, keep the standard prompt and update the installed conda

so it should be:

RUN curl -o ~/miniconda.sh -O  https://repo.anaconda.com/miniconda/Miniconda3-py38_23.11.0-2-Linux-x86_64.sh  && \
     chmod +x ~/miniconda.sh && \
     ~/miniconda.sh -b -p /opt/conda && \
     rm ~/miniconda.sh

ENV PATH /opt/conda/bin:$PATH

RUN conda config --set always_yes yes --set changeps1 no && conda update -q conda

# RUN pip install the python packages that were installed with apt-get ...

I don't think you need to uncomment the conda pytorch install line, I guess Wav2Lip install what it needs from the requirements file

@vido89
Copy link

vido89 commented Feb 18, 2025

@xenogenesi Oh I need to uncomment those lines in dockerfile-wav2lip. Ah sorry about that, I did not looked it carefully

@vido89
Copy link

vido89 commented Feb 18, 2025

@xenogenesi

11.14   Downloading opencv_contrib_python-4.11.0.86-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (20 kB)
11.52 ERROR: Ignored the following yanked versions: 3.4.11.39, 3.4.17.61, 4.4.0.42, 4.4.0.44, 4.5.4.58, 4.5.5.62, 4.7.0.68
11.52 ERROR: Could not find a version that satisfies the requirement opencv-python==4.1.0.25 (from versions: 3.4.0.14, 3.4.10.37, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.63, 3.4.18.65, 4.3.0.38, 4.4.0.40, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.60, 4.5.5.64, 4.6.0.66, 4.7.0.72, 4.8.0.74, 4.8.0.76, 4.8.1.78, 4.9.0.80, 4.10.0.82, 4.10.0.84, 4.11.0.86)
11.94 ERROR: No matching distribution found for opencv-python==4.1.0.25
------
Dockerfile:47
--------------------
  45 |     WORKDIR /workspace/Wav2Lip
  46 |     RUN pip3 install --upgrade pip
  47 | >>> RUN pip3 install -r requirements.txt
  48 |     
  49 |     RUN mkdir -p /root/.cache/torch/checkpoints && \
--------------------
ERROR: failed to solve: process "/bin/sh -c pip3 install -r requirements.txt" did not complete successfully: exit code: 1

Edit: I dont have conda in /opt/

@vido89
Copy link

vido89 commented Feb 18, 2025

@xenogenesi Oh sorry I was editing wrong file, but still opencv-python==4.1.0.25 is not available, closest available is 4.1.2.30 but here you tried that version and it gave you an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment