-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile.chr-qemu
More file actions
44 lines (34 loc) · 2.08 KB
/
Copy pathDockerfile.chr-qemu
File metadata and controls
44 lines (34 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
FROM alpine:3.21.3
# Runs RouterOS CHR in QEMU using simple user-mode networking (no tap/bridge needed).
# Uses virtio disk (qcow2) and virtio-net — both supported by MikroTik CHR on x86/amd64.
# Build with: docker build --build-arg ARG_ROUTEROS_VERSION=7.22 -t chr-qemu -f Dockerfile.chr-qemu .
# Run with: docker run --rm -d --device /dev/kvm -p 9180:80 -p 9122:22 chr-qemu
# Get RouterOS as argument for build
ARG ARG_ROUTEROS_VERSION="7.14.3"
# Expose RouterOS ports (Docker -p maps these to host ports)
EXPOSE 80 22 23 443 8728 8729 8291 5900 1194 1701 1723 1812/udp 1813/udp 4500/udp 500/udp 21 8080 8900
# Change work dir (will create if not exist)
WORKDIR /routeros
# Install only what we need: QEMU system emulator, qemu-img for conversion, unzip, bash
RUN apk add --no-cache qemu-system-x86_64 qemu-img unzip bash
# Environments which may be changed
ENV ROUTEROS_VERSION="${ARG_ROUTEROS_VERSION}"
ENV ROUTEROS_IMAGE="chr-${ARG_ROUTEROS_VERSION}.qcow2"
# Download VDI image - try download.mikrotik.com first (stable releases like "7.22"),
# then fall back to cdn.mikrotik.com (beta/rc/testing like "7.22rc2" or "7.22beta4").
# Versions without qualifiers (e.g. "7.22") are only on download.mikrotik.com.
RUN wget -q "https://download.mikrotik.com/routeros/${ROUTEROS_VERSION}/chr-${ROUTEROS_VERSION}.vdi.zip" \
-O "chr-${ROUTEROS_VERSION}.vdi.zip" \
|| (rm -f "chr-${ROUTEROS_VERSION}.vdi.zip" && \
wget -q "https://cdn.mikrotik.com/routeros/${ROUTEROS_VERSION}/chr-${ROUTEROS_VERSION}.vdi.zip" \
-O "chr-${ROUTEROS_VERSION}.vdi.zip")
RUN unzip -q "chr-${ROUTEROS_VERSION}.vdi.zip" && rm -f "chr-${ROUTEROS_VERSION}.vdi.zip"
# Convert VDI to qcow2 (native QEMU format, works well with virtio drivers)
RUN qemu-img convert -f vdi -O qcow2 \
"chr-${ROUTEROS_VERSION}.vdi" \
"chr-${ROUTEROS_VERSION}.qcow2" \
&& rm -f "chr-${ROUTEROS_VERSION}.vdi"
# Copy entrypoint script from this repo (no external Docker image dependency)
COPY scripts/entrypoint.sh /routeros/entrypoint.sh
RUN chmod +x /routeros/entrypoint.sh
ENTRYPOINT ["/routeros/entrypoint.sh"]