This tutorial will guide you step-by-step to deploy Ollama on a virtual machine (VM) using Docker and connect it with n8n to automate workflows.
Requirements: Ensure your VM has at least 4 GB of RAM. If the VM does not have enough memory, the download of the deepseek-coder model will fail.
- Docker installed on your VM.
- n8n deployed using Docker.
- Access to your VM's terminal.
To run Docker commands without sudo, add your user to the Docker group:
sudo usermod -aG docker $USERNote: After adding the user to the Docker group, log out and log back in for the changes to take effect.
Ensure the correct permissions are set for the n8n data volume:
sudo chown -R 1000:1000 /var/lib/docker/volumes/n8n_data/_data
sudo chmod -R 700 /var/lib/docker/volumes/n8n_data/_dataThis grants the appropriate permissions for n8n to access its data.
Run the following command to download the official Ollama image from Docker Hub.
docker pull ollama/ollamaThis command downloads the latest version of Ollama.
Now run the Ollama container and expose port 11434.
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollamaExplanation:
-d: Runs the container in detached mode.-v ollama:/root/.ollama: Creates a persistent volume for the downloaded models.-p 11434:11434: Maps port11434of the container to the VM.--name ollama: Names the container ollama.
Create a custom Docker network named n8n_network.
docker network create n8n_networkThis allows n8n and Ollama to communicate with each other.
Connect both n8n and Ollama to the n8n_network.
docker network connect n8n_network n8ndocker network connect n8n_network ollamaInspect the network to ensure both containers are connected.
docker network inspect n8n_networkYou should see n8n and ollama listed in the containers section.
docker exec -it ollama bashInside the Ollama container, run:
ollama listThis will display the models you have downloaded.
If the model is not downloaded, run it to start the download:
ollama run deepseek-coderIf you need to remove the deepseek-coder model to free up space or update it, run the following command inside the Ollama container:
ollama rm deepseek-coderTo get a specific version of an Ollama model, replace MODEL_NAME with the desired model name:
ollama run MODEL_NAME:3.2For example, to download version 3.2 of a model named ollama, run:
ollama run llama3.2:1bollama run deepseek-r1:1.5bexitTo check if Ollama is running:
docker ps -aIf Ollama is stopped, restart it:
docker start ollamaIf you want restart n8n stopped, restart it:
docker stop n8ndocker start n8nWhen configuring the Ollama node in n8n, ensure the base URL points to the container name Ollama instead of localhost.
Correct URL:
http://ollama:11434
To ensure n8n can communicate with Ollama:
- Access the n8n container:
docker exec -it n8n bash- Run a
curlcommand to test the connection:
curl http://ollama:11434If you receive a response, the connection is working correctly.
-
Issue: The Ollama container stops automatically.
- Solution: Check the logs to identify the error:
docker logs ollama
- Ensure you have at least 4 GB of RAM on the VM.
- Solution: Check the logs to identify the error:
-
Issue: n8n cannot connect to Ollama.
- Solution: Ensure both containers are on the
n8n_networkand use the URLhttp://ollama:11434.
- Solution: Ensure both containers are on the
Done! You now have Ollama running locally on your VM and connected with n8n to automate your workflows.