Skip to content

Instantly share code, notes, and snippets.

@belthesar
Created January 14, 2024 05:30
Show Gist options
  • Save belthesar/708f11ab25729f46a0734a93bfaaca3e to your computer and use it in GitHub Desktop.
Save belthesar/708f11ab25729f46a0734a93bfaaca3e to your computer and use it in GitHub Desktop.
Mikrotik Container Update Script
:local containerToUpdate
:set $containerToUpdate "name-of-container"
:local containerVeth
:set $containerVeth "container-veth-interface"
:local containerImage
:set $containerImage "org/image:tag"
:local containerEnvlist
:set $containerEnvlist "name-of-envlist"
:local containerMounts
:set %containerMounts "name-of-mount"
# Stop Container
/container/stop [find where comment~$containerToUpdate]
# Wait for container(s) to stop
:while ( [/container print count-only where comment~$containerToUpdate status=stopping] > 0) do={ :delay 1 }
# Remove old Container(s)
/container/remove [find where comment~$containerToUpdate]
# short delay
:delay 3
# create new container
/container/add interface=$containerVeth remote-image=$containerImage mounts=$containerMounts envlist=$containerEnvlist start-on-boot=yes logging=yes comment=$containerToUpdate
:delay 1
# Wait for new container to be ready
:while ( [/container print count-only where comment~$containerToUpdate status=extracting] > 0 ) do { :delay 1 }
# Start the new container
/container/start [find where comment~$containerToUpdate]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment