Skip to main content
If you have Docker installed, you can use the Recursion Tree Visualiser without manually installing Python, Graphviz, or other dependencies. This approach provides a consistent, isolated environment across different operating systems.

Prerequisites

Before using the Docker installation method, ensure you have:
  • Docker installed (download here)
  • Docker Compose installed (usually included with Docker Desktop)
  • Basic familiarity with command-line operations

Installation

The Docker setup uses two files: a Dockerfile for building the image and a docker-compose.yml file for running the container.
1

Download the Dockerfile

Download the Dockerfile from the repository:
curl https://raw.githubusercontent.com/Bishalsarang/Recursion-Tree-Visualizer/master/Dockerfile --output Dockerfile
The Dockerfile contains:
FROM python:3.6-slim
RUN apt-get update
RUN apt-get -y install graphviz
ADD . /vs
WORKDIR /vs
RUN pip install recursion-visualiser
2

Download the docker-compose.yml

Download the docker-compose configuration:
curl https://raw.githubusercontent.com/Bishalsarang/Recursion-Tree-Visualizer/master/docker-compose.yml --output docker-compose.yml
The docker-compose.yml contains:
version: "3.6"
services:
  vs:
    build: .
    container_name: recursion-visualiser-env
    stdin_open: true
    tty: true
    user: ${CURRENT_UID}
    volumes:
      - .:/vs
3

Start the Docker container

Build and start the container with the following command:
CURRENT_UID=$(id -u):$(id -g) docker-compose up
This command:
  • Sets the container user to match your current user ID (prevents permission issues)
  • Builds the Docker image (first time only)
  • Starts the container in the background
The first time you run docker-compose up, it will download the base Python image and install all dependencies. This may take a few minutes.

Running Python scripts

Once the container is running, you can execute Python scripts inside it using docker-compose exec.

Basic usage

docker-compose exec vs python your_script.py

Example: Running fibonacci.py

Create a file named fibonacci.py in your current directory:
from visualiser.visualiser import Visualiser as vs

@vs(node_properties_kwargs={
    "shape": "record",
    "color": "#f57542",
    "style": "filled",
    "fillcolor": "grey"
})
def fib(n):
    if n <= 1:
        return n
    return fib(n=n - 1) + fib(n=n - 2)

def main():
    print(fib(n=6))
    vs.make_animation("fibonacci.gif", delay=2)

if __name__ == "__main__":
    main()

Understanding the Docker setup

The Dockerfile

The Dockerfile defines the environment:
FROM python:3.6-slim
Starts from a minimal Python 3.6 image.
RUN apt-get update
RUN apt-get -y install graphviz
Installs Graphviz, the only system dependency required.
ADD . /vs
WORKDIR /vs
Copies your current directory into /vs in the container and sets it as the working directory.
RUN pip install recursion-visualiser
Installs the recursion-visualiser package from PyPI.

The docker-compose.yml

The docker-compose file simplifies container management:
services:
  vs:
    build: .
Builds the image from the Dockerfile in the current directory.
    user: ${CURRENT_UID}
Runs the container as your current user, preventing file permission issues.
    volumes:
      - .:/vs
Mounts your current directory to /vs in the container, allowing the container to read your scripts and write output files.
    stdin_open: true
    tty: true
Keeps the container running and allows interactive use.

Common Docker commands

Start the container (if stopped)

CURRENT_UID=$(id -u):$(id -g) docker-compose up -d
The -d flag runs the container in detached mode (background).

Stop the container

docker-compose down

Restart the container

docker-compose restart

View container logs

docker-compose logs -f vs

Access the container shell

For interactive debugging or exploration:
docker-compose exec vs /bin/bash
Once inside, you can run Python commands directly:
python fibonacci.py
ls -la
# etc.
Exit the shell with exit or Ctrl+D.

Remove the container and image

To completely remove the Docker setup:
# Stop and remove containers
docker-compose down

# Remove the image
docker rmi recursion-visualiser-env_vs

File permissions

The CURRENT_UID=$(id -u):$(id -g) environment variable ensures that files created by the container are owned by your user, not root.
Always use CURRENT_UID=$(id -u):$(id -g) when starting the container to avoid permission issues with generated files.

Working with examples

The repository includes several example scripts. Here’s how to run them using Docker:
# Clone the repository (if you haven't already)
git clone https://github.com/Bishalsarang/Recursion-Tree-Visualizer.git
cd Recursion-Tree-Visualizer

# Start the container
CURRENT_UID=$(id -u):$(id -g) docker-compose up -d

# Run different examples
docker-compose exec vs python examples/fibonacci.py
docker-compose exec vs python examples/factorial.py
docker-compose exec vs python examples/coin_change.py
docker-compose exec vs python examples/combinations.py

Advantages of Docker installation

1

No dependency conflicts

The Docker container provides an isolated environment, preventing conflicts with other Python packages or Graphviz versions on your system.
2

Consistent across platforms

The same Docker setup works on Linux, macOS, and Windows, eliminating platform-specific installation issues.
3

Easy cleanup

Remove the entire environment with a single command: docker-compose down && docker rmi recursion-visualiser-env_vs
4

Reproducible environment

The Dockerfile specifies exact versions, ensuring consistent behavior across different machines and times.

Troubleshooting

Permission denied errors

Problem: Cannot read/write files, or files are owned by root. Solution: Always use CURRENT_UID when starting the container:
CURRENT_UID=$(id -u):$(id -g) docker-compose up

Container not starting

Problem: docker-compose up fails or exits immediately. Solution: Check Docker daemon is running:
docker ps  # Should list running containers
sudo systemctl start docker  # Linux
# or start Docker Desktop on macOS/Windows

Module not found errors

Problem: ModuleNotFoundError: No module named 'visualiser' Solution: Rebuild the container to reinstall dependencies:
docker-compose down
docker-compose build --no-cache
CURRENT_UID=$(id -u):$(id -g) docker-compose up

Port conflicts

The default setup doesn’t expose any ports, but if you modify it and encounter port conflicts:
# Check what's using the port
sudo lsof -i :PORT_NUMBER

# Stop conflicting service or change port in docker-compose.yml

Out of disk space

Problem: Docker build fails due to insufficient space. Solution: Clean up unused Docker resources:
# Remove unused containers, networks, images
docker system prune -a

# Check disk usage
docker system df

Comparison: Docker vs. Native installation

AspectDockerNative Installation
Setup time~5-10 minutes (first time)~5-15 minutes (varies by OS)
DependenciesOnly Docker requiredPython, pip, Graphviz, packages
IsolationComplete isolationShares system Python
UpdatesRebuild containerUpdate packages individually
File accessVia volume mountsDirect access
PerformanceSlight overheadNative performance
Cross-platformIdentical across platformsPlatform-specific steps
Use Docker if you want a clean, isolated environment or work across multiple machines. Use native installation if you need maximum performance or already have Python and Graphviz installed.

Build docs developers (and LLMs) love