|
| 1 | +This article is about: |
| 2 | +- Running Hatchling with Docker |
| 3 | +- Setting up and configuring Ollama for local LLMs |
| 4 | +- Understanding Hatchling's environment variables and configuration options |
| 5 | + |
| 6 | +You will learn about: |
| 7 | +- How to start Ollama with CPU or GPU support |
| 8 | +- Downloading and building Hatchling from source |
| 9 | +- Configuring environment variables for your needs |
| 10 | +- Starting and using Hatchling with Docker Compose |
| 11 | +# Running Hatchling |
| 12 | + |
| 13 | +This section assumes you have followed the [docker setup](./docker-setup.md). |
| 14 | + |
| 15 | +In this guide, you will: |
| 16 | + |
| 17 | +1. Start Ollama to have access to local LLMs later in Hatchling. |
| 18 | +2. Download, setup, and start Hatchling |
| 19 | + |
| 20 | +## Running Ollama with Docker |
| 21 | + |
| 22 | +### Using CPU or GPU for the LLM |
| 23 | + |
| 24 | +* Windows/Linux **CPU only** & MacOS **on Apple Silicon**: |
| 25 | + |
| 26 | + ```bash |
| 27 | + docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama |
| 28 | + ``` |
| 29 | + |
| 30 | +* Windows/Linux **NVIDIA GPU support**: |
| 31 | + |
| 32 | + ```bash |
| 33 | + docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama |
| 34 | + ``` |
| 35 | + |
| 36 | +* Windows/Linux **AMD GPU support**: |
| 37 | + |
| 38 | + ```bash |
| 39 | + docker run -d --device /dev/kfd --device /dev/dri -v ollama:/ root/.ollama -p 11434:11434 --name ollama ollama/ollama:rocm |
| 40 | + ``` |
| 41 | + |
| 42 | +### Checking that GPU support is enabled as expected |
| 43 | + |
| 44 | +* Go to the `Containers` tab in Docker Desktop (arrow 1) and select your Ollama container |
| 45 | + |
| 46 | + * Check the logs and search for a message indicating GPU detection, similar to: |
| 47 | + |
| 48 | + ```txt |
| 49 | + msg="inference compute" id=GPU-a826c853-a49e-a55d-da4d-804bfe10cdcf library=cuda variant=v12 compute=8.6 driver=12.7 name="NVIDIA GeForce RTX 3070 Laptop GPU" total="8.0 GiB" available="7.0 GiB" |
| 50 | + ``` |
| 51 | +
|
| 52 | +  |
| 53 | +* Alternatively, run the command `docker logs ollama` and search for the message in the output. |
| 54 | +
|
| 55 | +For more detailed instructions and options, refer to the [official Ollama Docker documentation](https://github.com/ollama/ollama/blob/main/docs/docker.md). |
| 56 | +
|
| 57 | +## Running Hatchling with Docker |
| 58 | +
|
| 59 | +### Get the source code |
| 60 | +
|
| 61 | +At this step, you will be downloading the content of Hatchling. Currently, we are only using GitHub's interface to install Hatchling. |
| 62 | +
|
| 63 | +* Open a terminal |
| 64 | +* Navigate to a directory where you want Hatchling to be: |
| 65 | +
|
| 66 | + ```bash |
| 67 | + cd path/to/the/directory/you/want |
| 68 | + ``` |
| 69 | + |
| 70 | +* Then, use Git, to retrieve the source code |
| 71 | + |
| 72 | + ```bash |
| 73 | + git clone https://github.com/CrackingShells/Hatchling.git |
| 74 | + ``` |
| 75 | + |
| 76 | +### Navigate to the `docker` directory of Hatchling |
| 77 | + |
| 78 | +```bash |
| 79 | +cd ./Hatchling/docker |
| 80 | +``` |
| 81 | + |
| 82 | +### Install Hatchling by building the code |
| 83 | + |
| 84 | + ```bash |
| 85 | + docker-compose build hatchling |
| 86 | + ``` |
| 87 | + |
| 88 | + This typically takes 20 to 50 seconds depending on your computer. |
| 89 | + |
| 90 | +### Start Hatchling |
| 91 | + |
| 92 | +#### Configure Hatchling's Environment |
| 93 | + |
| 94 | +Modify the variables in the `.env` file to suit your needs. |
| 95 | + |
| 96 | +#### Configuration |
| 97 | + |
| 98 | +Configuration is managed through environment variables or a `.env` file in the `docker` directory: |
| 99 | + |
| 100 | +| Variable | Description | Default | |
| 101 | +|----------|-------------|---------| |
| 102 | +| `OLLAMA_HOST_API` | URL for the Ollama API | `http://localhost:11434/api` | |
| 103 | +| `OLLAMA_MODEL` | Default LLM model to use | `llama3.2` | |
| 104 | +| `HATCH_HOST_CACHE_DIR` | Directory where Hatch environments and cache will be stored on the host machine | `./.hatch` | |
| 105 | +| `HATCH_LOCAL_PACKAGE_DIR` | Directory where local packages are stored on the host machine to be accessible in the container | `../../Hatch_Pkg_Dev` | |
| 106 | +| `NETWORK_MODE` | Docker network mode | `host` (for Linux) | |
| 107 | +| `LOG_LEVEL` | The default log level at start up | `INFO` | |
| 108 | +| `USER_ID` | User ID for the container user (set on Linux to match host user for permissions) | `1000` | |
| 109 | +| `GROUP_ID` | Group ID for the container user (set on Linux to match host group for permissions) | `1000` | |
| 110 | +| `USER_NAME` | Username for the container user (optional, defaults to `appuser`) | `appuser` | |
| 111 | + |
| 112 | +##### OLLAMA_HOST_API |
| 113 | + |
| 114 | +You may need to adjust `OLLAMA_HOST_API` to match where your Ollama container is hosted. If you did not change this value and used the default from [earlier](#using-cpu-or-gpu-for-the-llm), then you don't need to change that variable either. |
| 115 | + |
| 116 | +##### OLLAMA_MODEL |
| 117 | + |
| 118 | +For hatchlings, one can change `OLLAMA_MODEL` to any model under the category [tools](https://ollama.com/search?c=tools) |
| 119 | + |
| 120 | +> [!Warning] |
| 121 | +> Be mindful of the size of the LLM. Models larger than your GPU's memory (VRAM on GPU cards, or the partition of the shared memory that can be allocated to GPU tasks on Apple Silicon), will not run smoothly. You can check the actual size of a model when selecting a model on the within [the list](https://ollama.com/search?c=tools) |
| 122 | +
|
| 123 | + |
| 124 | + |
| 125 | +For example, [earlier](#checking-that-gpu-support-is-enabled--as-expected) the GPU's available memory was indicated to be 7GB. Therefore, this GPU can load up to `deepseek-r1:8b`, which happens to be the default (marked as `latest`). |
| 126 | + |
| 127 | +#### Ollama |
| 128 | + |
| 129 | +* On Docker Desktop, navigate to your containers (arrow 1), and press the play button (arrow 2) |
| 130 | + |
| 131 | +* Alternatively, run the command `docker start ollama` |
| 132 | + |
| 133 | +#### Hatchling |
| 134 | + |
| 135 | +> [!Note] |
| 136 | +> You can adapt the [environment variables](#configuration) to suit your needs (e.g. change the LLM) before you run the following command: |
| 137 | +
|
| 138 | +```bash |
| 139 | +# From the docker directory in your project |
| 140 | +docker-compose run --rm hatchling #The `--rm` flag ensures the container is removed when you exit the application. |
| 141 | +``` |
| 142 | + |
| 143 | +If Hatchling successfully connects to Ollama, it will download the specified LLM model. This will materialize by many prints indicating the download progress. Of course, the download time varies based on the model's size: the default model `llama3.2` takes about 2GB. |
| 144 | + |
| 145 | +Here is a screenshot of what Hatchling typically looks like right after start up: |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | +You can receive help about all available commands by writing `help` in the chat. Details about the commands are also available in the [documentation](./chat_commands.md) |
0 commit comments