Community discussions

MikroTik App
 
mbrad
just joined
Topic Author
Posts: 10
Joined: Wed Jun 18, 2014 5:40 am

Docker built containers won't work on Mikrotik

Sun Dec 29, 2024 8:29 am

I am attempting to run a small container on a RB5009UG+S+ running ROS 7.16.2 (have also tried on ROS 7.17rc3). When I add the container:
/container add file=usb2/myimage.tar root-dir=usb2/myimage interface=veth3
I get these results in the log:
importing tar archived image: myimage.tar
error getting layer file
failed to load next entry
import finished but no image found
I can successfully pull remote images from Docker hub and run them on RB5009 with results as expected, so I'm fairly confident I have the device (and veth's and bridges, etc.) set up correctly. I can successfully build and run my Docker container on my desktop. But the image won't extract or load properly on the RB5009 from a .tar that I supply.

My Dockerfile (below) is very simple and I don't suspect the binary I'm using is the culprit as it's very small. I've even tried a "blank" alpine image (a little trickier because the container needs something to run) and I always get the same extraction error on loading.
FROM arm64v8/alpine:latest
COPY mybinary /mybinary

EXPOSE 1234/tcp

CMD ["/mybinary", "-v"]
I'm using this command to build:
docker buildx build --no-cache --platform linux/arm64 -t myimage .
And then I export with this command:
docker save myimage > myimage.tar
Any suggestions? Does anyone else have success building arm64 images on a Windows machine with Docker desktop and then running on a Mikrotik device?
 
User avatar
patrikg
Member
Member
Posts: 397
Joined: Thu Feb 07, 2013 6:38 pm
Location: Stockholm, Sweden

Re: Docker built containers won't work on Mikrotik

Sun Dec 29, 2024 12:00 pm

Why not try first some examples from the doc.
And maybe you missed the --output options to output docker image.

https://help.mikrotik.com/docs/spaces/R ... nimageonPC
 
mbrad
just joined
Topic Author
Posts: 10
Joined: Wed Jun 18, 2014 5:40 am

Re: Docker built containers won't work on Mikrotik

Mon Dec 30, 2024 12:18 am

Thanks, I've been using the docs to get started. I updated my build command to:
docker buildx build --no-cache --platform linux/arm64 --output=type=docker -t myimage .
But the results are the same, error getting layer file and no image found as soon as it's added. Every remote image I pull from docker hub runs fine on my Mikrotik. Every local image I build myself runs fine locally on Windows (emulating arm64 just fine).

Just stumped getting a local build to run on the RB5009. :(
 
User avatar
tangent
Forum Guru
Forum Guru
Posts: 1691
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Docker built containers won't work on Mikrotik

Mon Dec 30, 2024 3:17 am

Comparing what you've done to my successful Makefile, I see a few possible explanations:

  • Use of "buildx" instead of "build". The distinctions are collapsing as BuildKit becomes the default, but in this instance you don't need any of the advanced features of the old BuildKit, in particular multi-platform builds.
  • Single-step build-and-save. Try doing without the --output flag, building into the local image cache and then doing a separate "docker image save" step.
  • OCI vs legacy Docker tarball format. They don't document the format of "docker image save", but I would have guessed "oci" these days, not "docker" as you have it. A single-step build-and-save might work if you switch to type=oci.

I haven't tried breaking my build to find out which of these actually matters. I leave that as an exercise for the student. 😛 Please do report back once you discover the culprit, for our mutual enlightenment.

Failing all this, passing the tarball through Skopeo per my "limitations" guide might fix your tarball. I've seen this succeed more than once.

(And a complete reading of the guide should prove enlightening, if tangential to this thread's purpose.)
 
mbrad
just joined
Topic Author
Posts: 10
Joined: Wed Jun 18, 2014 5:40 am

Re: Docker built containers won't work on Mikrotik

Mon Dec 30, 2024 4:36 am

Thanks for weighing in tangent. I tried a few variations as below, starting with building and exporting all at once as a .tar:
docker buildx build --no-cache --platform linux/arm64 --output=type=tar,dest=myimage.tar -t myimage .
This produces a .tar file with a flat directory structure: \bin, \dev, \etc, \home. I didn't expect this would work as there was no place any additional metadata could be stored such as the command to run on launch. As expected, when I tried the /container add command, it immediately shot back with "failure: could not import". The log also showed "error: could not find image manifest in archive"

Next I tried building and exporting as type=oci:
docker buildx build --no-cache --platform linux/arm64 --output=type=oci,dest=myimage.tar -t myimage .
This produces a .tar file containing just oci-layout, index.json, and a blobs folder. The results were the same as above with the exact same errors. Lack of a manifest in the root of the .tar is immediately catastrophic.

Last I tried building and exporting as type=docker:
docker buildx build --no-cache --platform linux/arm64 --output=type=docker,dest=myimage.tar -t myimage .
This produces a .tar file containing oci-layout, index.json, manifest.json, and a blobs folder. This seems to get a little closer, but the failures are the same as I reported in my first post: log lines indicating there's an error getting the layer file and no image to be found. Doesn't seem to have gotten me any closer yet.
 
User avatar
tangent
Forum Guru
Forum Guru
Posts: 1691
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Docker built containers won't work on Mikrotik  Topic is solved

Mon Dec 30, 2024 5:25 am

That leaves you with two further options, then: the separate build+save method, optionally coupled with a Skopeo pass.

Now that I've had time to think about it, the second option is feeling more likely to result in success.

There's a third option: push to Docker Hub, then have ROS pull the image remotely. container.npk is designed around this path, which is why everyone else's builds work while your local-only ones don't.
 
mbrad
just joined
Topic Author
Posts: 10
Joined: Wed Jun 18, 2014 5:40 am

Re: Docker built containers won't work on Mikrotik

Mon Dec 30, 2024 9:55 am

The skopeo tip seems to have worked. I had to get into WSL and install it (apk add skopeo) first. It produces a .tar file approximately double in size that is structured in a much more complicated manner inside, but when the archive file gets transferred to Mikrotik, it does import and works!

I have some more testing to do to make sure I have a repeatable process and that I understand all the moving pieces. Many thanks for the pointer, I would never have been able to figure out that by default Docker produces images incompatible with Mikrotik containers.
 
yamako
just joined
Posts: 1
Joined: Fri Nov 03, 2023 1:04 pm

Re: Docker built containers won't work on Mikrotik

Wed Feb 12, 2025 1:56 pm

I have been through this issue before. The problem might be with how the image is saved or extracted on the RB5009. Try using `docker save myimage -o myimage.tar` instead of `docker save myimage > myimage.tar`. Also, make sure the USB drive is correctly mounted and has enough space. You can check by running `disk print` in RouterOS. Another thing to try is loading the image manually by extracting it on your desktop first, then copying the layers to the RB5009. Let me know if this helps.
Last edited by yamako on Wed Feb 12, 2025 1:57 pm, edited 1 time in total.