Containter status, script to auto update containers

Hi, my script stopped working on RouterOS 7.20.1.

/ip dns 
set servers=8.8.8.8

/container/stop [find where comment~"pihole"] 
:while ( [/container print count-only where comment~"pihole" status=stopping] > 0) do={ :delay 1 }
/container/remove [find where comment~"pihole"]
:delay 5
/container/add interface="veth1" remote-image="pihole/pihole:latest" mounts="MOUNT_PIHOLE_PIHOLE,MOUNT_PIHOLE_DNSMASQD" envlist="ENV_PIHOLE" root-dir="usb1/images/pihole" start-on-boot=yes logging=yes comment="pihole"
:delay 3
:while ( [/container print count-only where comment~"pihole" status=extracting] > 0 ) do { :delay 1 }
/container/start [find where comment~"pihole"]

/ip dns 
set servers=192.168.88.21

There is a problem with “status=stopping”. When I paste it to the terminal it’s coloured red. Is there any way to get container status?

First, in 7.20 you don't need to look for string in comment to identify containers anymore, you can give them proper name, like pihole for example. Then in the command you can directly reference them, like:

/container shell pihole
/container stop pihole
/container start pihole

Second is that there is no status property anymore, but flags. stopping, stopped, starting, running are now flags. And you can use them like this:

/container print where running
/container start [find stopped]
/container print count-only where extracting

You can also execute commands inside the container and return result to the caller script:

:local output [/container shell alpine cmd="ls -a /" no-sh as-value]; :put $output;
1 Like

Nice, thank you.

And most important, as this is an update script:

Since 7.20 you can use

/container/repull <name|number>

2 Likes

Yes, but also currently repull has the bug that it forgets to put the .type file to the root of the repull-ed container, so all the files and directories are visible when you look at them in WinBox, instead of collapsing into a single container store node.

A fix for now would be to manually create .type file at the root with container as content, by running something like this in the shell.

echo container > /.type

Ahhh, I already wondered why I see all the container file system when /files/print. Silly bug.