Customizing the Official MikroTik Cloud Hosted Router Image for ContainerLab
It's been a little over a year since I posted my previous article about using vrnetlab to run MikroTik CHR VMs in ContainerLab. Last year I was jealous of my friends in the US celebrating Thanksgiving. This year it's Black Friday. Perhaps I should be out shopping, but I just can't bring myself to face that kind of crazy. It'll wait.
Since then, MikroTik has created their own official Docker container for the CHR, starting with the 7.22 release of RouterOS. Before we get too excited, no it's not an actual container-based CHR. (I had hopes, but there's just too much kernel tweaking going on in RouterOS to be able to run it natively in a container under a generic kernel.) It does have a few advantages over the old vrnetlab configuration that I appreciate:
- There's no need to build the Docker image manually
- The management interface is bridged into ContainerLab's management network rather than relying on container-based port forwarding
It also has a couple of downsides that I think need to be fixed:
- Pulling the official image using the long-term, stable, testing, and development tags doesn't tag the image with the actual version number
- The official image only includes the base RouterOS package and doesn't provide an easy way to incorporate additional packages without doing so manually after the container has been started
Following the same pattern as the previous article, let's look at how to use the official Docker image effectively beginning with the downsides mentioned above.
Version Tagging
The Docker container can be pulled down a number of ways. We can request a specific version (back to 7.22) or grab the latest image based on the channel name.
~$ docker pull mikrotik/chr:7.24.77.24.7: Pulling from mikrotik/chr
Digest:
sha256:d2680bc94819f1a5ba7f3ad076510a3121e0da16f22119817bafcf69ff54c2a5
Status: Downloaded newer image for mikrotik/chr:7.24.7
docker.io/mikrotik/chr:long-term ~$ docker pull mikrotik/chr:long-term
long-term: Pulling from mikrotik/chr
Digest:
sha256:d2680bc94819f1a5ba7f3ad076510a3121e0da16f22119817bafcf69ff54c2a5
Status: Downloaded newer image for mikrotik/chr:long-term
docker.io/mikrotik/chr:long-term
The above commands accomplish the same thing, but I prefer the first one because it preserves the version number in the image name. This makes it easy to test specific versions against one another. The channel tag can also be added to the specific version that I've downloaded so that I can reference images using either method.
~$ docker tag mikrotik/chr:7.24.7 mikrotik/chr:long-termIf you pulled your image based on the channel tag, it's just as easy to assign the version number to that by reversing the order of the previous command.
~$ docker tag mikrotik/chr:long-term mikrotik/chr:7.24.7Optional RouterOS Packages
When we were running vrnetlab-based CHR images, we had to build a custom image if we wanted all of the optional packages baked in. Using the official container isn't much different in principle, but we're not building Docker images based on our own VM images anymore and so the process isn't quite the same.
Build Steps
These steps assume that you already have Docker installed and running and that you're using a user that has privileges to manage your Docker installation. If you're not there yet, take a moment to get that done before proceeding.
Launch the CHR Container
We'll need to start the default CHR container image to add the optional packages. The command below will handle that. If you haven't manually pulled the image into the local Docker image repository, Docker will retrieve it from Docker Hub and add it to the local repository.
~$ docker run -d --name chr-builder --tty --interactive --device /dev/kvm --privileged mikrotik/chr:7.24.71e2bcfaff4c402bbd9d3809a50a9e183dbffe617016e52a2772befecacaa18c9
Now that the container has started, we need to pull its address assignments from Docker to manually configure the CHR's management interface in a later step.
~$ docker inspect chr-builder -f '{{range .NetworkSettings.Networks}}{{printf "Address: %s/%d\nGateway: %s\n" .IPAddress .IPPrefixLen .Gateway}}{{end}}'Address: 172.17.0.2/16
Gateway: 172.17.0.1
Attach to the CHR Container
~$ docker attach chr-builderLogin To the CHR
Once connected to the container, we'll be presented with a login prompt. The default username on a CHR is "admin" and there is no default password, so just hit enter for this.
MikroTik 7.24.7 (long-term)MikroTik Login: admin
Password:
The splash screen and a prompt asking if we want to read the license will appear. I've read it before, so I skip that part. By all means read it if this is your first time.
RouterOS 7.24.7 (c) 1999-2026 https://www.mikrotik.com/Do you want to see the software license? [Y/n]: n
Next we'll be prompted to change the password. We won't be keeping the system configuration when we're done here, so there's no point. Just press Ctrl-C to skip this and go to the initial prompt.
Change your passwordnew password>
[admin@CHR] >
Configure the Management Network
The CHR Docker image relies on external orchestration to set the management network's address, default gateway, and DNS servers. We're bypassing all of that to make this custom image, so we have to enter it manually using the information we gathered from Docker earlier.
[admin@CHR] > /ip[admin@CHR] /ip> address/add address=address interface=ether1
[admin@CHR] /ip> route/set gateway=gateway
[admin@CHR] /ip> dns/set servers=8.8.8.8,8.8.4.4
Add Optional Packages
Next, we'll install all of the optional packages.
[admin@CHR] > /system/package[admin@CHR] /system/package> update/check-for-updates
channel: long-term
installed-version: 7.24.7
latest-version: 7.24.7
status: System is already up to date
We just pulled the Docker image moments ago, so there won't likely be any updates but the check will update the packages list, which is the important part. Executing the "print" command in the /system/packages context will show us all of the packages, marked as disabled but available.
[admin@CHR] /system/package> printFlags: X - DISABLED; A - AVAILABLE
Columns: NAME, VERSION, BUILD-TIME, SIZE
# NAME VERSION BUILD-TIME SIZE
0 routeros 7.24.7 2026-11-19 08:42:49 19.9MiB
1 XA calea 24.1KiB
2 XA container 1148.1KiB
3 XA dude 1392.1KiB
4 XA gps 24.1KiB
5 XA iot 580.1KiB
6 XA netinstall 76.1KiB
7 XA openflow 80.1KiB
8 XA rose-storage 5.0MiB
9 XA tr069-client 156.1KiB
10 XA ups 36.1KiB
11 XA user-manager 408.1KiB
12 XA wireless 1136.1KiB
There are a number of packages here that will probably never be needed in a ContainerLab installation, but I'm not going to assume anyone's lab requirements. We'll just enable them all, make sure that they're scheduled, and apply the changes.
[admin@CHR] /system/package> enable [find][admin@CHR] /system/package> print where scheduled~"apply-changes"
Flags: X - DISABLED; A - AVAILABLE
Columns: NAME, SCHEDULED, SIZE
# NAME SCHEDULED SIZE
1 XA calea Use "apply-changes" to proceed with install 24.1KiB
2 XA container Use "apply-changes" to proceed with install 1148.1KiB
3 XA dude Use "apply-changes" to proceed with install 1392.1KiB
4 XA gps Use "apply-changes" to proceed with install 24.1KiB
5 XA iot Use "apply-changes" to proceed with install 580.1KiB
6 XA netinstall Use "apply-changes" to proceed with install 76.1KiB
7 XA openflow Use "apply-changes" to proceed with install 80.1KiB
8 XA rose-storage Use "apply-changes" to proceed with install 5.0MiB
9 XA tr069-client Use "apply-changes" to proceed with install 156.1KiB
10 XA ups Use "apply-changes" to proceed with install 36.1KiB
11 XA user-manager Use "apply-changes" to proceed with install 408.1KiB
12 XA wireless Use "apply-changes" to proceed with install 1136.1KiB
[admin@CHR] /system/package> apply-changes
Apply scheduled changes and reboot device? [y/N]:
y
system will reboot shortly
Verify Packages
We'll repeat the same login process we went through when we first launched the CHR container. As before, there's no need to actually set an admin password. We'll be resetting the configuration when we're done here, so there's no point.
Next, we'll switch to the /system/package context and verify that the packages are installed.
[admin@CHR] > /system/package/printColumns: NAME, VERSION, BUILD-TIME, SIZE
# NAME VERSION BUILD-TIME SIZE
0 iot 7.24.7 2026-11-19 08:42:49 580.1KiB
1 openflow 7.24.7 2026-11-19 08:42:49 80.1KiB
2 dude 7.24.7 2026-11-19 08:42:49 1392.1KiB
3 calea 7.24.7 2026-11-19 08:42:49 24.1KiB
4 container 7.24.7 2026-11-19 08:42:49 1148.1KiB
5 tr069-client 7.24.7 2026-11-19 08:42:49 156.1KiB
6 user-manager 7.24.7 2026-11-19 08:42:49 408.1KiB
7 wireless 7.24.7 2026-11-19 08:42:49 1136.1KiB
8 netinstall 7.24.7 2026-11-19 08:42:49 76.1KiB
9 ups 7.24.7 2026-11-19 08:42:49 36.1KiB
10 routeros 7.24.7 2026-11-19 08:42:49 19.9MiB
11 rose-storage 7.24.7 2026-11-19 08:42:49 5.0MiB
12 gps 7.24.7 2026-11-19 08:42:49 24.1KiB
If we see output similar to the above, all optional packages have loaded correctly and we're ready for the next step.
Reset the CHR's Configuration
Now that we have verified that the packages have been installed, we'll reset the CHR's configuration and shut it down to prepare it to be saved to a new Docker image.
[admin@CHR] > /system/reset-configuration keep-apps=no keep-users=no skip-backup=yes no-defaults=yes shutdown=yesThe container will now shut down and Docker will drop us back to our host's prompt.
Save the Container as a New Image
We can now take our newly-created container and save it as an image for future use.
~$ docker commit chr-builder mikrotik/chr:7.24.7-fullsha256:b0972746a8a02a8443f3cc0f0d6164de278b1b2a3b30d0623ae539e2afe099fc
Tag the New Image
After committing, we can tag the new image with the appropriate channel name and verify that everything is correctly listed in our repository.
~$ docker tag mikrotik/chr:7.24.7-full mikrotik/chr:long-term-full~$ docker image ls mikrotik/chr:7.24.7-full
REPOSITORY TAG IMAGE ID CREATED SIZE
mikrotik/chr 7.24.7-full 03e4e462c3ca 5 minutes ago 364MB
~$ docker image ls mikrotik/chr:long-term-full
REPOSITORY TAG IMAGE ID CREATED SIZE
mikrotik/chr long-term-full 03e4e462c3ca 5 minutes ago 364MB
Clean Up
Not that the image has been committed to the repository and verified, we can remove our build container.
~$ docker rm chr-buildStreamlining
So, all we need to do is repeat the process for every new MikroTik CHR version in every release channel every time there's an update. We'll need to do it for every other version we might want to test, too. Easy, right? No.
It was worthwhile to do this once to get a feel for the process, but nobody wants to do this every single time. We are living in an age of automation. Let's automate a bit.
I've created two scripts to cover all of this for us and have made them available on GitHub. They can be found in the ghostinthenet/docker-chr-scripts repository.
getimage.py
This script will pull a specific CHR version from Docker Hub into the local repository and will use the above process to build a second image with all of the optional packages, which it will then commit to the local repository as well.
getlatest.py
This script will check MikroTik's upgrade site for the latest version of the CHR image in each release channel. If that version and its optional packages version aren't already present in the local repository, it will use the getimage.py script to add both and add the appropriate release tags. Older images will be left with their version tags.
The Whisper in the Wires
Using the official MikroTik image in ContainerLab streamlines a few things, most notably eliminating the need for an additional layer in vrnetlab. I'll be using this going forward now that I've addressed the annoying bits.
Having the management interface of the CHR connected to the ContainerLab management network opens up some possibilities for WinBox. I'm already labbing that up for the next post. Stay tuned.
Leave a comment on the Fediverse, BlueSky Reddit or LinkedIn and let me know what you think.