Community discussions

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

Problem with a Script for Containers

Wed Oct 12, 2022 11:43 am

I wanted to automate a container start and container shell command in mirkotik scripting. I want to scan the hostname and status of the container. I wrote a code wich should work but it doesn t and I don t know why. i first tried just looking at the hostname but it doesn t work either. the if statement just doesn t run and i get no log output.
:local myName do={:put "hostname";:return};
:local myCon do={:put "container";:return};
:local userinput [$myName];
:local containerlist [$myCon];
:local var1 [/container find count-only where hostname=$userinput]];
:if ( $var1 = "0") do ={ 
/container start $containerlist;
/container shell $containerlist;
:log info "is  running";
} else {
:log info "doesn't work";
}
 
karaYusuf
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Wed Oct 12, 2022 11:07 am

Re: Problem with a Script for Containers

Thu Oct 13, 2022 3:07 pm

I want to post this because maybe someone could need it.
I found a much better script wich is very simple and working good.
:local myCon do={:put "container"; :return};
:local containerlist [$myCon];
:put "Docker is running";
/container start $containerlist;
/container shell $containerlist;
delay 1;
/container stop $containerlist;
It will stop the container the moment you exit the shell.
This is needed because there is a bug in the Terminal in the version I am using (RouterOS v7.6rc1) if u run a container wich is already running. With stopping it while exiting the shell, there is never a posibility to get that bug.

Who is online

Users browsing this forum: mbezuidenhout, UkRainUa and 19 guests