Nugget: Prepare your Docker-Compose Stack as a Tarball for Offline Installations
Requirements
Many a times you might have requirement to run Docker on a Raspberry Pi or other SBCs that may
have to do run some applications without any internet connections. You might have initially
developed your application only by keeping in mind a Docker Artifact and was meant to run as
complete stack using docker-compose.yml
.
In almost all cases, bringing the stack up will pull the images from a registry through the Internet. But when you wish to deploy some SBCs into a space where there is no Internet to begin with you might have to either develop your code artifact as a package or binary bundle. If this application requires dependencies on some Databases then you will have to write tedious bash scripts to prepare the device for some pre-installtion.
Seems like a lot of refactoring / re-thinking to do!
Do not worry docker
has things sorted out, and provides docker save
and docker load
functionalities.
Scenario
Let’s consider an Open-Source Stack tiguitto for IoT at Edge.
It comprises of some standard apps like an MQTT Broker, InfluxDB, Telegraf, Grafana. All these
components are combined through a docker-compose.yml
file.
Now, as previously mentioned shipping the stack would have been easy, had we had Internet on the target node. Simply sending the compose file to the node would have done everything for us.
For cases where we do not have Internet access, we have to ship two things:
docker-compose.yml
- Compressed Tar-Ball for services present in the compose file
Usage Steps
Assume we have our development machine with docker
and docker-compose
on them.
We make sure to remove all not-used, unnecessary images are cleared from the machine and only the images of our application exists.
docker images -a # check existing images on dev machine
If you wish to remove everything and only pull the required images do:
docker rmi $(docker images | awk "NR>0 {print$3}")
Pull the images with their dedicated tags using
docker pull <image_name>:<tag>
Check using
docker images -a
Now leverage
docker save
along with some format parsing using:docker save -o myStack.tar $(docker images --format "{{.Repository}}:{{.Tag}}")
docker save
combines the image into their respective Tar balls however we need to tell docker
that we need to combine all the images existing on the dev machine into a combined Tar ball. This
is done through --format "{{.Repository}}:{{.Tag}}"
- This should produce
myStack.tar
in your directory
Unpack your Tarball and Test
If you are doing this on a laptop or PC, try switching your network connection off now.
- Unpack your Tarball
docker load -i myStack.tar
Check with
docker images -a
You can now
docker-compose up
and your application should work offline
If you use some other ways of using shipping your Docker and Compose applications, get in touch with me and would like to learn from you!