|
| 1 | +.. _using_docker_image: |
| 2 | + |
| 3 | +======================= |
| 4 | +Xinference Docker Image |
| 5 | +======================= |
| 6 | + |
| 7 | +Xinference provides official images for use on Dockerhub. |
| 8 | + |
| 9 | + |
| 10 | +Prerequisites |
| 11 | +============= |
| 12 | +* The image can only run in an environment with GPUs and CUDA installed, because Xinference in the image relies on CUBLAS for acceleration. |
| 13 | +* CUDA must be successfully installed on the host machine. This can be determined by whether you can successfully execute the ``nvidia-smi`` command. |
| 14 | +* The CUDA version in the docker image is ``12.1``, and the CUDA version on the host machine should ideally be consistent with it. Be sure to keep the CUDA version on your host machine between ``11.8`` and ``12.2``, even if it is inconsistent. |
| 15 | + |
| 16 | + |
| 17 | +Docker Image |
| 18 | +============ |
| 19 | +The official image of Xinference is available on DockerHub in the repository ``xprobe/xinference``. |
| 20 | +There are two kinds of image tags available: |
| 21 | + |
| 22 | +* ``nightly-main``: This image is built daily from the `GitHub main branch <https://github.com/xorbitsai/inference>`_ and generally does not guarantee stability. |
| 23 | +* ``v<release version>``: This image is built each time a Xinference release version is published, and it is typically more stable. |
| 24 | + |
| 25 | + |
| 26 | +Dockerfile for custom build |
| 27 | +=========================== |
| 28 | +If you need to build the Xinference image according to your own requirements, the source code for the Dockerfile is located at `xinference/deploy/docker/Dockerfile <https://github.com/xorbitsai/inference/tree/main/xinference/deploy/docker/Dockerfile>`_ for reference. |
| 29 | +Please make sure to be in the top-level directory of Xinference when using this Dockerfile. For example: |
| 30 | + |
| 31 | +.. code-block:: bash |
| 32 | +
|
| 33 | + git clone https://github.com/xorbitsai/inference.git |
| 34 | + cd inference |
| 35 | + docker build --progress=plain -t test -f xinference/deploy/docker/Dockerfile . |
| 36 | +
|
| 37 | +
|
| 38 | +Image usage |
| 39 | +=========== |
| 40 | +You can start Xinference in the container like this, simultaneously mapping port 9997 in the container to port 9998 on the host, enabling debug logging, and disabling vllm. |
| 41 | + |
| 42 | +.. code-block:: bash |
| 43 | +
|
| 44 | + docker run -e XINFERENCE_DISABLE_VLLM=1 -p 9998:9997 --gpus all xprobe/xinference:v<your_version> xinference-local -H 0.0.0.0 --log-level debug |
| 45 | +
|
| 46 | +
|
| 47 | +.. warning:: |
| 48 | + * The option ``--gpus`` is essential and cannot be omitted, because as mentioned earlier, the image requires the host machine to have a GPU. Otherwise, errors will occur. |
| 49 | + * The ``-H 0.0.0.0`` parameter after the ``xinference-local`` command cannot be omitted. Otherwise, the host machine may not be able to access the port inside the container. |
| 50 | + * You can add multiple ``-e`` options to introduce multiple environment variables. |
| 51 | + |
| 52 | + |
| 53 | +Certainly, if you prefer, you can also manually enter the docker container and start Xinference in any desired way. |
| 54 | + |
| 55 | + |
| 56 | +Mount your volume for loading and saving models |
| 57 | +=============================================== |
| 58 | +The image does not contain any model files by default, and it downloads the models into the container. |
| 59 | +Typically, you would need to mount a directory on the host machine to the docker container, so that Xinference can download the models onto it, allowing for reuse. |
| 60 | +In this case, you need to specify a volume when running the Docker image and configure environment variables for Xinference: |
| 61 | + |
| 62 | +.. code-block:: bash |
| 63 | +
|
| 64 | + docker run -v </on/your/host>:</on/the/container> -e XINFERENCE_HOME=</on/the/container> -p 9998:9997 --gpus all xprobe/xinference:v<your_version> xinference-local -H 0.0.0.0 |
| 65 | +
|
| 66 | +
|
| 67 | +The principle behind the above command is to mount the specified directory from the host machine into the container, and then set the ``XINFERENCE_HOME`` environment variable to point to that directory inside the container. |
| 68 | +This way, all downloaded model files will be stored in the directory you specified on the host machine. |
| 69 | +You don't have to worry about losing them when the Docker container stops, and the next time you run it, you can directly use the existing models without the need for repetitive downloads. |
0 commit comments