Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List used images from Docker Compose

I want to distribute a Docker Compose system as a single archive. For this I want to run docker save on all the images. But how do I get the list of images from Docker Compose?

This is what I do at the moment:

IMAGES=$(cat docker-compose.yml | sed -n 's/image:\(.*\)/\1/p')
docker save -o images.tar $IMAGES
like image 257
Daniel Darabos Avatar asked Oct 16 '25 07:10

Daniel Darabos


2 Answers

Here is a solution using docker compose convert. This is helpful, as it will expand any environment variables used to define your images in the compose file.

IMAGES=( $(docker compose convert --images) )
docker save ${IMAGES[@]} | gzip > images.tar.gz
like image 198
Clint Chelak Avatar answered Oct 18 '25 01:10

Clint Chelak


Do the following:

# Save Compressed Images
IMAGES=`grep '^\s*image' docker-compose.yml | sed 's/image://' | sort | uniq`

docker save $IMAGES | gzip > images.tar.gz

# Load Compressed Images
gunzip -c images.tar.gz | docker load
like image 28
Cuong Tran Avatar answered Oct 18 '25 01:10

Cuong Tran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!