|
| 1 | +# Streamlit Chatbot with Ollama (LLaMA 3.2:1B) on Docker |
| 2 | + |
| 3 | + |
| 4 | +## Prerequisites |
| 5 | + |
| 6 | +- Docker installed on your system |
| 7 | +- Basic knowledge of Docker commands |
| 8 | + |
| 9 | +## 1. Build the Streamlit Chatbot Docker Image |
| 10 | + |
| 11 | +### Build the Docker Image |
| 12 | + |
| 13 | +Run the following command in the same directory as the `Dockerfile`: |
| 14 | + |
| 15 | +```sh |
| 16 | +docker build -t ai-chatbot . |
| 17 | +``` |
| 18 | + |
| 19 | +## 2. Run Ollama on Docker |
| 20 | + |
| 21 | +To run Ollama with the LLaMA 3.2:1B model, execute: |
| 22 | + |
| 23 | +```sh |
| 24 | +docker run -d --name ollama -p 11434:11434 ollama/ollama:latest |
| 25 | +``` |
| 26 | + |
| 27 | +Pull and prepare the LLaMA 3.2:1B model: |
| 28 | + |
| 29 | +```sh |
| 30 | +docker exec -it ollama ollama pull llama3:1b |
| 31 | +``` |
| 32 | + |
| 33 | +## 3. Run the Streamlit Chatbot Container |
| 34 | + |
| 35 | +Once Ollama is running, start the chatbot container: |
| 36 | + |
| 37 | +```sh |
| 38 | +docker run -d --name chatbot -p 8501:8501 streamlit-chatbot |
| 39 | +``` |
| 40 | + |
| 41 | +Get the Container IP of the Ollama Container |
| 42 | + |
| 43 | +Get the Container ID |
| 44 | +``` |
| 45 | +docker ps |
| 46 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 47 | +2cf4d51a43c9 ollama/ollama "/bin/ollama serve" 2 minutes ago Up 2 minutes 0.0.0.0:11434->11434/tcp ollama |
| 48 | +``` |
| 49 | +Get the IP |
| 50 | + |
| 51 | +In Windows |
| 52 | +``` |
| 53 | +docker inspect 2cf4d51a43c9 | findstr IPAddress |
| 54 | +``` |
| 55 | +On Linux/Mac |
| 56 | +``` |
| 57 | +docker inspect 2cf4d51a43c9 | grep IPAddress |
| 58 | +``` |
| 59 | + |
| 60 | +## 4. Access the Chatbot |
| 61 | + |
| 62 | +Open your browser and visit: |
| 63 | + |
| 64 | +``` |
| 65 | +http://localhost:8501 |
| 66 | +``` |
| 67 | +Update the Backend URL |
| 68 | + |
| 69 | +## 5. Stop and Remove Containers |
| 70 | + |
| 71 | +To stop and remove all running containers: |
| 72 | + |
| 73 | +```sh |
| 74 | +docker stop ai-chatbot ollama && docker rm ai-chatbot ollama |
| 75 | +``` |
| 76 | + |
| 77 | + |
0 commit comments