Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcataluna/1dc2f31694a1c301ab34dac9ccb385ea to your computer and use it in GitHub Desktop.
Save jcataluna/1dc2f31694a1c301ab34dac9ccb385ea to your computer and use it in GitHub Desktop.
Script to save all images from a docker-compose.yml file
#!/bin/bash
mkdir -p out
for img in `grep image $1| sed -e 's/^.*image\: //g'`;
do
cleanname=${img/\//-}
tag=`docker images | grep $img | awk '{print $2}'`
echo "Exporting image: $img, tag:$tag ($cleanname)..."
docker save $img -o out/$cleanname.tar
ls -lah out/$cleanname.tar
tar -czvf out/$cleanname.tgz out/$cleanname.tar
rm -rf out/$cleanname.tar
done
@hlavki
Copy link

hlavki commented Oct 6, 2017

#!/bin/bash

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
  images="$images $img"
done

docker save -o services.img $images

@daveneeley
Copy link

daveneeley commented May 17, 2018

powershell

$images = @(); docker-compose config | ?{$_ -match "image:.*$"} | %{$images += ($_ -replace "image: ", "").Trim()}; docker save -o services.img $images

@mortezaf
Copy link

docker save -o services.img $images

Excellent
You saved my time

@McPo
Copy link

McPo commented Mar 21, 2019

@hlavki solution as a one liner

docker save -o docker-images.tar $(docker-compose config | awk '{if ($1 == "image:") print $2;}' ORS=" ")

@dragonhaimax
Copy link

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
  images="$images $img"
done

docker save -o services.img $images

And then, how can I use the file services.img?
I want to use 'docker load ' to load these images.
The first step is to unzip service.img?

@sayanarijit
Copy link

@McPo ORS=" " can be dropped here.

docker save -o docker-images.tar $(docker-compose config | awk '{if ($1 == "image:") print $2;}')

@rjendoubi
Copy link

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
  images="$images $img"
done

docker save -o services.img $images

And then, how can I use the file services.img?
I want to use 'docker load ' to load these images.
The first step is to unzip service.img?

docker load < services.img

🙂

@GPla
Copy link

GPla commented May 30, 2023

Compose V2 offers --images to list all images (even the ones build by the compose file).

#!/bin/bash

for img in $(docker compose config --images); do
  images="$images $img"
done

docker save -o services.img $images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment