2018-08-22 15:59:29 +03:00
# Mikrotik RouterOS in Docker
2024-02-17 10:54:41 +03:00
This project comprises a Docker image that runs a MikroTik's RouterOS
virtual machine inside QEMU.
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
It's designed to simulate MikroTik's RouterOS environment, making it an
excellent tool for development and testing purposes, especially for those
working with the RouterOS API.
2018-08-22 15:59:29 +03:00
2024-02-17 10:54:41 +03:00
This Docker image is particularly useful for unit testing the
[routeros-api-php ](https://github.com/EvilFreelancer/routeros-api-php ) library, allowing developers to test applications
in a controlled environment that closely mimics a real RouterOS setup.
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
For users seeking a fully operational RouterOS environment for production
use within Docker, the [VR Network Lab ](https://github.com/plajjan/vrnetlab ) project is recommended
as an alternative.
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
## Getting Started
### Pulling the Image from Docker Hub
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
To use the image directly from Docker Hub, you can pull it and run a
container as shown below. This will start a RouterOS instance with ports
configured for SSH, API, API-SSL, and VNC access.
2018-08-23 18:09:23 +03:00
```bash
docker pull evilfreelancer/docker-routeros
2019-02-05 22:04:05 +03:00
docker run -d -p 2222:22 -p 8728:8728 -p 8729:8729 -p 5900:5900 -ti evilfreelancer/docker-routeros
2018-08-23 18:09:23 +03:00
```
2024-02-17 10:54:41 +03:00
### Use in `docker-compose.yml`
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
For those preferring docker-compose, an example configuration is provided
below. More examples is [here ](docker-compose.dist.yml ).
2019-01-11 17:24:19 +03:00
2018-08-23 18:09:23 +03:00
```yml
2024-02-17 10:54:41 +03:00
version: "3.9"
2018-08-23 18:09:23 +03:00
services:
2024-02-17 10:54:41 +03:00
routeros:
image: evilfreelancer/docker-routeros:latest
2018-08-23 18:09:23 +03:00
restart: unless-stopped
2020-04-14 21:26:01 +03:00
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
2024-02-17 10:54:41 +03:00
- /dev/kvm
2018-08-23 18:09:23 +03:00
ports:
2024-02-17 10:54:41 +03:00
- "2222:22"
- "23:23"
- "80:80"
- "5900:5900"
- "8728:8728"
- "8729:8729"
```
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
### Creating a Custom `Dockerfile`
You can easily create your own Dockerfile to include custom scripts or
configurations. The Docker image supports various tags, which are listed
[here ](https://hub.docker.com/r/evilfreelancer/docker-routeros/tags/ ).
By default, the `latest` tag is used if no tag is specified.
2019-01-11 17:24:19 +03:00
2024-02-17 10:54:41 +03:00
```dockerfile
FROM evilfreelancer/docker-routeros
ADD ["your-scripts.sh", "/"]
RUN /your-scripts.sh
2018-08-23 18:09:23 +03:00
```
2024-02-17 10:54:41 +03:00
### Building from Source
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
If you prefer to build the Docker image from source, the commands below
will guide you through cloning the repository, building the image, and
running a RouterOS container.
2018-08-23 18:09:23 +03:00
```bash
git clone https://github.com/EvilFreelancer/docker-routeros.git
cd docker-routeros
docker build . --tag ros
2019-02-05 22:04:05 +03:00
docker run -d -p 2222:22 -p 8728:8728 -p 8729:8729 -p 5900:5900 -ti ros
2018-08-23 18:09:23 +03:00
```
2024-02-17 10:54:41 +03:00
After launching the container, you can access your RouterOS instance
via VNC (port 5900) and SSH (port 2222).
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
## Exposed Ports
2018-08-23 18:09:23 +03:00
2024-02-17 10:54:41 +03:00
The table below summarizes the ports exposed by the Docker image,
catering to various services and protocols used by RouterOS.
| Description | Ports |
|-------------|---------------------------------------|
2020-04-14 21:22:39 +03:00
| Defaults | 21, 22, 23, 80, 443, 8291, 8728, 8729 |
2024-02-17 10:54:41 +03:00
| IPSec | 50, 51, 500/udp, 4500/udp |
| OpenVPN | 1194/tcp, 1194/udp |
| L2TP | 1701 |
| PPTP | 1723 |
2018-08-23 18:09:23 +03:00
2020-04-14 21:22:39 +03:00
## Links
2019-02-05 22:04:05 +03:00
2024-02-17 10:54:41 +03:00
For more insights into Docker and virtualization technologies
related to RouterOS and networking, explore the following resources:
* [Mikrotik RouterOS in Docker using Qemu ](https://habr.com/ru/articles/498012/ ) - An article on Habr that provides a guide on setting up Mikrotik RouterOS in Docker using Qemu, ideal for developers and network engineers interested in RouterOS virtualization.
* [RouterOS API Client ](https://github.com/EvilFreelancer/routeros-api-php ) - GitHub repository for the RouterOS API PHP library, useful for interfacing with MikroTik devices.
* [VR Network Lab ](https://github.com/vrnetlab/vrnetlab ) - A project for running network equipment in Docker containers, recommended for production-level RouterOS simulations.
* [qemu-docker ](https://github.com/joshkunz/qemu-docker ) - A resource for integrating QEMU with Docker, enabling virtual machine emulation within containers.
* [QEMU/KVM on Docker ](https://github.com/ennweb/docker-kvm ) - Demonstrates using QEMU/KVM virtualization within Docker containers for improved performance.