Run Network Simulator 2 (NS-2.35) with NAM GUI inside Docker. Zero setup, 100% reproducible. Perfect for students, researchers, or legacy network labs.
Network Simulator 2 (NS-2.35) is a popular discrete event simulator for network research, but it often fails to compile on modern systems. This Docker image provides a plug-and-play environment with full GUI support, eliminating the setup hassle.
- Quick-start
- Features
- Usage Options: Two Ways to Use NS-2
- Running Simulations
- Wayland Support
- Project Structure
- Why Use Docker for NS2?
- Troubleshooting
- Maintainer
- Show Your Support
- Credits
- License
By default, the host directory for ns-2 script is $HOME/workspace/ns-2/scripts
. If the directory is not present in your machine, the following command will create one for you and it will be auto mounted to /root/scripts
in the container.
Note: NAM uses a GUI. Ensure your system supports X11 forwarding (e.g. X11/XWayland on Linux).
On your host machine:
docker pull abidmuin/ns-2.35 && \
git clone https://github.com/abidmuin/ns-2.git && \
cd ns-2 && \
mkdir -p $HOME/workspace/ns-2/scripts && \
chmod +x run-ns2.sh && \
./run-ns2.sh \
Then, inside the container:
cd /root/scripts
ns sample.tcl && nam out.nam
NAM GUI displaying a running simulation inside Docker with X11 forwarding.
- Pre-configured NS-2.35 with NAM GUI.
- Lightweight Docker container.
- GUI support even on Wayland via X11 forwarding.
- Mount host directory to
/root/scripts
for running your.tcl
or.cpp
script simulations. - Includes patch for known
ls.h
compilation issue. - Two usage options: pre-built image or build it yourself.
Option 1: Use Pre-Built Docker Image (Recommended)
- Pull the image from Docker Hub
docker pull abidmuin/ns-2.35
- Clone this repo to get the run script
git clone https://github.com/abidmuin/ns-2.git && cd ns-2
- Run NS2 with GUI support
./run-ns2.sh
This script will:
- Grant X11 access for GUI (NAM)
- Mounts your local
$HOME/workspace/ns-2/scripts
directory into the container at/root/scripts
for easy access to simulation files. The location can be modified in therun-ns2.sh
script by changingHOST_SCRIPTS_DIR
value.
- Mounts your local
Option 2: Build the Image Locally
- Clone the repository
git clone https://github.com/abidmuin/ns-2.git && cd ns-2
- Build the image
docker build -t abidmuin/ns-2.35 .
- Run it
./run-ns2.sh
A working sample.tcl
is included in the scripts/
directory for testing.
Inside the container:
cd /root/scripts
ns sample.tcl && nam out.nam
All your .tcl
or .cpp
simulation scripts go into your host-side directory: $HOME/workspace/ns-2/scripts
Even if your host uses Wayland (echo $XDG_SESSION_TYPE
returns wayland
), the container uses X11 via XWayland, and GUI applications like NAM work as expected.
GUI access is granted using xhost
.
xhost +local:root
docker run ...
xhost -local:root
This is already handled in run-ns2.sh
. If NAM fails to launch, ensure xhost +local:root
was successful and your Docker host allows X11 forwarding.
Note:
xhost +local:root
is required for GUI apps in Docker, but remember to runxhost -local:root
afterward to restore security.
.
├── Dockerfile # Docker build script
├── run-ns2.sh # Launch script (GUI + mount setup)
├── README.md # You're reading it!
└── scripts/ # (Optional) Your simulation scripts
Without Docker | With Docker |
---|---|
Old GCC, OTcl, Tk issues | Pre-installed & configured |
Platform-specific bugs | Works on any Docker platform |
GUI breaks on Wayland | GUI patched & tested |
Manual patching required | Auto-patched in Dockerfile |
-
NAM doesn’t launch / GUI errors
- Make sure X11 forwarding is working and
xhost +local:root
was successful. - On Wayland, ensure you have XWayland installed.
- Make sure X11 forwarding is working and
-
Permission denied when mounting host directory
- Try running with
sudo
, or ensure your user has Docker permissions.
- Try running with
Abid Hasan Muin
Email: muin.739@gmail.com
Feel free to open an issue if you encounter any problem or have suggestions.
If this project saved you time or simplified your workflow, feel free to:
- Star this repo.
- Share it on LinkedIn or with your classmates/research group.
- Original NS2 Source: SourceForge and ISI
- Sample TCL script: Mark Greis' Tutorial
- Patches & Docker Integration: @abidmuin
This project is licensed under the MIT License.