Community discussions

MikroTik App
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Container status on error

Wed Nov 09, 2022 11:57 am

Hello,
I wanted to add a websockify container with a remote-image on my mikrotik hapac2, wich i pushed to dockerhub before. My problem is that i can not run the container after adding the container. The status of the container is on "error".

The image link for the remote image is:
https://hub.docker.com/r/karayusuf29/we ... _arm_v7_32

To add the container i did this :
/interface/veth/add name=veth1 address=192.168.1.150/24 gateway=192.168.1.1;

#creating bridge and assign the bridge an ip
/interface/bridge/add name=dockers;
/ip/address/add address=10.0.0.1/24 interface=dockers;

#connecting the  veth-interface with the bridge
/interface/bridge/port add bridge=dockers interface=veth1;

#creating firewall
/ip/firewall/nat/add chain=srcnat action=masquerade src-address=172.17.0.0/16;

#creating environment and mounts parameters
/container/envs/add name=websockify_envs key=PASSWD value=letmein;
/container/mounts/add name=websockify_data src=disk1/docker/websockify_data dst=/data;


#is required for some containers to run a bit more stable
/container/config set ram=100

#is required for remote image
/container/config/set registry-url=https://registry-1.docker.io tmpdir=disk1/pull

#
/container/add remote-image=karayusuf29/websockify_docker_image_arm_v7_32 interface=veth1  root-dir=disk2/docker/websockify_root mounts=websockify_data envlist=websockify_envs logging=yes hostname=Websockif
I looked in the log info and found this :
Image

What can i do to get the container running?
 
tangent
Forum Guru
Forum Guru
Posts: 1329
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Container status on error

Wed Nov 09, 2022 1:48 pm

You've got a device with 16 MiB of flash and you're trying to load a 290 MiB container. I'm guessing it's trying to download the image to the internal flash and failing. You might have to "export" the image using Docker Desktop, upload that to the USB drive thru scp or WinBox, then use the "/container add file=" syntax.

I assume this "disk2" you reference is a USB drive of some type, but I don't see anything that forces RouterOS to use that for downloading the container image.

Hopefully this external drive is a gig or bigger for so piggy a container. It isn't well-optimized. I see Perl and GCC and Git and all kinds of other stuff you don't need running on the final container. Would you care to share the Dockerfile? Maybe we can get it down to something small enough to download into internal flash, then unpack onto your USB drive.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Container status on error

Thu Nov 10, 2022 10:48 am

You've got a device with 16 MiB of flash and you're trying to load a 290 MiB container. I'm guessing it's trying to download the image to the internal flash and failing. You might have to "export" the image using Docker Desktop, upload that to the USB drive thru scp or WinBox, then use the "/container add file=" syntax.

I assume this "disk2" you reference is a USB drive of some type, but I don't see anything that forces RouterOS to use that for downloading the container image.

Hopefully this external drive is a gig or bigger for so piggy a container. It isn't well-optimized. I see Perl and GCC and Git and all kinds of other stuff you don't need running on the final container. Would you care to share the Dockerfile? Maybe we can get it down to something small enough to download into internal flash, then unpack onto your USB drive.
Of course I can share my Docker file.
Here it is :
FROM python:3.6



ENV VERSION 0.10.0



RUN mkdir -p /opt/websockify \
    && curl -SL https://github.com/novnc/websockify/archive/refs/tags/v$VERSION.tar.gz \
    | tar xzC /opt/websockify



VOLUME /data



EXPOSE 80
EXPOSE 443



WORKDIR /opt/websockify



COPY docker-entrypoint.sh /



ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["tail -f /dev/null"]
It would be great if it would get a bit more minimized.

What i tried, is using a .rsc Script, wich can reset the router. It should work like a reset configuration script. I wanted to make it automatically so the router sets up everything needed without a manual configuration. Until now everything works the way its needed but i had to disconnect and reconnect the cable to the external storage(Harddrive 1TB) everytime after the reset. It doesnt list the storage after a reset if i don t reconnect it like that. After that i used the "/container add file=" syntax as u said to get the container on my hapac2.

Is there another way like a command, code or scheduler where i don t have to reconnect the cable of the external storage and make it automatically to download the container to that external storage?
 
tangent
Forum Guru
Forum Guru
Posts: 1329
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Container status on error

Thu Nov 10, 2022 12:07 pm

FROM python:3.6

There's your space problem, right there: you've indirectly based your container on the flabby buildpack-deps image, which accounts for essentially all of the space your container takes. Your actual application adds approximately zilch to the size of the base.

It's fine to use such base layers as-is when deploying to a big old Intel server, but with small RouterOS devices, it's worth learning how to do multi-stage builds with a slimmer base layer in the second stage. You can use tools like Wheel to turn the first-stage version of the application into an independent redistributable package, allowing you to discard the piggy base layer in the second stage.

You can keep using your current "FROM python:3.6" as the first stage, but you then say "FROM debian:stable-slim" (30 MiB) or "FROM alpine" (5 MiB) or "FROM scratch" (0.01 MiB) as the second stage, then unpack your finalized Websockify package atop it.


If you're going to start with a full-featured base image like Debian or Buildpack, you might as well use PIP to retrieve your Python deps.

Is there another way like a command, code or scheduler where i don t have to reconnect the cable of the external storage and make it automatically to download the container to that external storage?

Your problem description is hard to parse, but I suspect you can get the automation you need using SSH scripting, the REST API, or TR-069.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Container status on error

Thu Nov 10, 2022 2:57 pm

FROM python:3.6

There's your space problem, right there: you've indirectly based your container on the flabby buildpack-deps image, which accounts for essentially all of the space your container takes. Your actual application adds approximately zilch to the size of the base.

It's fine to use such base layers as-is when deploying to a big old Intel server, but with small RouterOS devices, it's worth learning how to do multi-stage builds with a slimmer base layer in the second stage. You can use tools like Wheel to turn the first-stage version of the application into an independent redistributable package, allowing you to discard the piggy base layer in the second stage.

You can keep using your current "FROM python:3.6" as the first stage, but you then say "FROM debian:stable-slim" (30 MiB) or "FROM alpine" (5 MiB) or "FROM scratch" (0.01 MiB) as the second stage, then unpack your finalized Websockify package atop it.


If you're going to start with a full-featured base image like Debian or Buildpack, you might as well use PIP to retrieve your Python deps.

Is there another way like a command, code or scheduler where i don t have to reconnect the cable of the external storage and make it automatically to download the container to that external storage?

Your problem description is hard to parse, but I suspect you can get the automation you need using SSH scripting, the REST API, or TR-069.
I want to say that I m new to this things at first. So i made a new dockerfile. I just added an alpine-dockerfile from dockerhub:
FROM python:3.6



ENV VERSION 0.10.0



RUN mkdir -p /opt/websockify \
    && curl -SL https://github.com/novnc/websockify/archive/refs/tags/v$VERSION.tar.gz \
    | tar xzC /opt/websockify



VOLUME /data



EXPOSE 80
EXPOSE 443



WORKDIR /opt/websockify



COPY docker-entrypoint.sh /



ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["tail -f /dev/null"]

FROM alpine:3.14
RUN apk add --no-cache mysql-client
ENTRYPOINT ["mysql"]
I got a .tar file and added the container. I looked in the shell and i think that the websockify application is not in there. But the thing is that i dont have any idea how to turn the first-stage version of the application into an independent redistributable package and combine it with the alpine dockerfile as second stage layer.

After adding the container I opend the shell with container start/shell commands. There i looked in the "opt"-file but nothing is in there. Thats why I think that the websockify aplication is not in it. And i get another Problem: The shell just says done and is closing randomly.
[admin@DISE_LAB11] > container start 1

[admin@DISE_LAB11] > container shell 1
/ # cd opt
/opt # ls
done
[admin@DISE_LAB11] >
It would be terrific if you could help me with this projekt I m going on right now.
 
tangent
Forum Guru
Forum Guru
Posts: 1329
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Container status on error

Thu Nov 10, 2022 3:44 pm

i looked in the "opt"-file but nothing is in there.

Yes, because you didn't read the multi-stage guide I linked you to above. As formulated, you've thrown the first stage away entirely, replacing it with the second stage. You need at least one "COPY" or "ADD" command in the second stage, referencing the first.

It would be terrific if you could help me with this projekt I m going on right now.

I can advise, but I'm not going to write it for you. You'll have to read the docs I referenced above and work most of this out on your own.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Container status on error

Fri Nov 11, 2022 12:16 pm

i looked in the "opt"-file but nothing is in there.

Yes, because you didn't read the multi-stage guide I linked you to above. As formulated, you've thrown the first stage away entirely, replacing it with the second stage. You need at least one "COPY" or "ADD" command in the second stage, referencing the first.

It would be terrific if you could help me with this projekt I m going on right now.

I can advise, but I'm not going to write it for you. You'll have to read the docs I referenced above and work most of this out on your own.
At first thank you for advising me :)

So I tried some things. I found out that if i want to run websockify on alpine i need a python package and it got more and more complicated. Thats why i just installed the alpine container on my pc instead of the router for test reasons. In that alpine container i connected it to the internet and downloaded websockify and python manually. It is now working on my pc. So i made a repository and pushed the .tar file to the docker hub. You can click here for the image in dockerhub. After that I added the container in the hapac2 Router with the "/container remote-image=" syntax. The new problem I get now is that it runs for a short time like milliseconds and stops running.

It looks like this in the terminal :
[admin@DISE_LAB11] > container start 0

[admin@DISE_LAB11] > container shell 0
container not running
If I do the commands fast enough the terminal shows me this:
[admin@DISE_LAB11] > container start 0

[admin@DISE_LAB11] > container shell 0
open: No such file or directory
done
What is the thing I m doing wrong? I do not understand why it is working on my pc but not on the router.
 
tangent
Forum Guru
Forum Guru
Posts: 1329
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Container status on error

Fri Nov 11, 2022 2:30 pm

i need a python package

That's one way. Another is linked indirectly above, PyInstaller. That packages the Python interpreter, your program, and any modules it requires into a self-contained package you can COPY over from the first-stage build.

This way, you might not even need Alpine as a base. If it will run "FROM scratch" this way, you'll save 5 MiB in your image, minimum. Likely more, since PyInstaller copies over only the parts of the Python runtime it thinks are necessary.

I believe that can be further optimized, because what I see here on a "hello world" program is still fatter than I think it ought to be.

Thats why i just installed the alpine container on my pc

That's the best way anyway. Don't deploy to RouterOS until you get things working under the full-featured container build system. You cause yourself unnecessary pain by shooting straight for the most restrictive environment.

On that same note, starting with a single-stage build is fine. You go with two-stage builds only once you see how fat the result is going to be, then deciding you need to optimize.

i made a repository and pushed the .tar file to the docker hub.

It's 21 MiB, meaning it still won't download to your router's internal flash. I'd try hard to get it under 16 MiB.

I don't mean to say that you shouldn't run it on external storage, but it's nice to use the internal flash as scratch space for setting up the container.

container start 0

The default "CMD" in that image is "/bin/sh", meaning it will start and then stop, having done nothing useful. Unless you pass cmd="…" to the "/container add" command to override that, that's exactly what you will get.

You should read my Containers Are Not VMs article. You appear to be falling into the class of traps it discusses.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Container status on error

Mon Nov 14, 2022 9:24 am

i need a python package

That's one way. Another is linked indirectly above, PyInstaller. That packages the Python interpreter, your program, and any modules it requires into a self-contained package you can COPY over from the first-stage build.

This way, you might not even need Alpine as a base. If it will run "FROM scratch" this way, you'll save 5 MiB in your image, minimum. Likely more, since PyInstaller copies over only the parts of the Python runtime it thinks are necessary.

I believe that can be further optimized, because what I see here on a "hello world" program is still fatter than I think it ought to be.

Thats why i just installed the alpine container on my pc

That's the best way anyway. Don't deploy to RouterOS until you get things working under the full-featured container build system. You cause yourself unnecessary pain by shooting straight for the most restrictive environment.

On that same note, starting with a single-stage build is fine. You go with two-stage builds only once you see how fat the result is going to be, then deciding you need to optimize.

i made a repository and pushed the .tar file to the docker hub.

It's 21 MiB, meaning it still won't download to your router's internal flash. I'd try hard to get it under 16 MiB.

I don't mean to say that you shouldn't run it on external storage, but it's nice to use the internal flash as scratch space for setting up the container.

container start 0

The default "CMD" in that image is "/bin/sh", meaning it will start and then stop, having done nothing useful. Unless you pass cmd="…" to the "/container add" command to override that, that's exactly what you will get.

You should read my Containers Are Not VMs article. You appear to be falling into the class of traps it discusses.
Thank you for your advice. It is very helpfull. I got an alpine-dockerfile and installed python in the entrypoint were the websockify.zip-data gets unzipped too. Now the shell of websockify works fine,but i have another question.
The following code is the dockerfile :
#!/bin/bash
FROM --platform=linux/arm64/v8 alpine:latest
COPY docker-entrypoint.sh /
RUN chmod +x docker-entrypoint.sh
RUN apk add python3 && apk add py3-pip
COPY websockify-0.10.0.zip /



ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["tail", "-f", "/dev/null"]
And the following code here is the entrypoint:
#!/bin/sh

mkdir -p /opt/websockify

mv websockify-0.10.0.zip /opt/websockify

cd /opt/websockify

unzip websockify-0.10.0.zip

cd websockify-master/

python3 setup.py install

tail -f /dev/null
Now to my question. I can start the container and use the websockify as I wanted to but only once, If I close the contnainer and start again it gets running for some milliseconds and stops randomly.
I used this line in my entrypoint to get the websockify started without stopping:
tail -f /dev/null
But how can I use or implement this command everytime Im starting the container, like
cmd="tail -f /dev/null"
 
tangent
Forum Guru
Forum Guru
Posts: 1329
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Container status on error

Mon Nov 14, 2022 2:37 pm

The following code is the dockerfile...#!/bin/bash

A Dockerfile isn't a Bash shell script. It contains shell script sections, but it won't run if you say "bash Dockerfile". Drop the shebang line; it makes a counterfactual declaration.

RUN apk add python3 && apk add py3-pip

You shouldn't need that if you're using PyInstaller in this way, with a single-stage build. You have a copy of Python in the installer package, and you no longer need PIP.

You would return to this if doing a two-stage build, creating the installer in the first stage and then using it in the second. The transition from the first stage to the second would throw away the Alpine layer, effectively uninstalling Python and PIP.

CMD ["tail", "-f", "/dev/null"]

You should be running websockify here with the options that cause it to start and keep running. Don't make me research what those are for you. It's your application; you tell me.

here is the entrypoint...mv websockify-0.10.0.zip /opt/websockify

If you're going to do a single-stage build, unpacking websockify is best done in the first stage, baking it into the image, not in the entrypoint, which doesn't run until the container is created from the image. At best, you're unpacking the installer each time you start your container. At worst, you'll cause problems with storage due to the repeated redundant unpacking.

If you take my initial advice and go with a two-stage build, you'd build the package in the first stage, COPY it over from the first to the second stage, unpack there in the second stage, and then run it either via CMD or ENTRYPOINT.

The choice between those two options and whether or not to combine them is complicated.
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Container status on error

Wed Nov 16, 2022 11:08 am

The following code is the dockerfile...#!/bin/bash

A Dockerfile isn't a Bash shell script. It contains shell script sections, but it won't run if you say "bash Dockerfile". Drop the shebang line; it makes a counterfactual declaration.

RUN apk add python3 && apk add py3-pip

You shouldn't need that if you're using PyInstaller in this way, with a single-stage build. You have a copy of Python in the installer package, and you no longer need PIP.

You would return to this if doing a two-stage build, creating the installer in the first stage and then using it in the second. The transition from the first stage to the second would throw away the Alpine layer, effectively uninstalling Python and PIP.

CMD ["tail", "-f", "/dev/null"]

You should be running websockify here with the options that cause it to start and keep running. Don't make me research what those are for you. It's your application; you tell me.

here is the entrypoint...mv websockify-0.10.0.zip /opt/websockify

If you're going to do a single-stage build, unpacking websockify is best done in the first stage, baking it into the image, not in the entrypoint, which doesn't run until the container is created from the image. At best, you're unpacking the installer each time you start your container. At worst, you'll cause problems with storage due to the repeated redundant unpacking.

If you take my initial advice and go with a two-stage build, you'd build the package in the first stage, COPY it over from the first to the second stage, unpack there in the second stage, and then run it either via CMD or ENTRYPOINT.

The choice between those two options and whether or not to combine them is complicated.
Right now I am trying some things out. If I get to the point were I do not have any ideas i will write u again. As you said I have to figure some things out for myself. I really appreciate your advice. Thank you for everything.
 
MavisMarchand
just joined
Posts: 1
Joined: Thu Apr 27, 2023 10:24 am

Re: Container status on error

Thu Apr 27, 2023 10:27 am




Yes, because you didn't read the multi-stage guide I linked you to above. As formulated, you've thrown the first stage away entirely, replacing it with the second stage. You need at least one "COPY" or "ADD" command in the second stage, referencing the first.





I can advise, but I'm not going to write it for you. You'll have to read the docs I referenced above and work most of this out on your own.
At first thank you for advising me :)

So I tried some things. I found out that if i want to run websockify on alpine i need a python package and it got more and more complicated. Thats why i just installed the alpine container on my pc instead of the router for test reasons. In that alpine container i connected it to the internet and downloaded websockify and python manually. It is now working on my pc. So i made a repository and pushed the .tar file to the docker hub. You can click here for the image in dockerhub. After that I added the container in the hapac2 Router with the "/container remote-image=" syntax. The new problem I get now is that it runs for a short time like milliseconds and stops running. nerdle

It looks like this in the terminal :
[admin@DISE_LAB11] > container start 0

[admin@DISE_LAB11] > container shell 0
container not running
If I do the commands fast enough the terminal shows me this:
[admin@DISE_LAB11] > container start 0

[admin@DISE_LAB11] > container shell 0
open: No such file or directory
done
What is the thing I m doing wrong? I do not understand why it is working on my pc but not on the router.
I found this post to be quite complete.

Who is online

Users browsing this forum: No registered users and 3 guests