Maps docker-compose.yml image vars to pinned digests using docker buildx bake metadata output.
241
Docker image that cross-references a docker-compose.yml with the metadata JSON from docker buildx bake --metadata-file to produce a .env file mapping each image variable to its resolved [email protected].
docker run --rm -v "$PWD":/workspace compose-tag [compose-file] [metadata-file] [output-file]
| Argument | Default | Description |
|---|---|---|
compose-file | docker-compose.yml | Compose file with ${VAR} image refs |
metadata-file | meta.json | Metadata JSON from docker buildx bake |
output-file | tags.env | Output .env file |
Given a docker-compose.yml:
services:
api:
image: ${API_IMAGE:-my-registry/api:latest}
web:
image: ${WEB_IMAGE:-my-registry/web:latest}
db:
image: postgres:16
And a meta.json (from docker buildx bake --metadata-file meta.json):
{
"api": {
"image.name": "my-registry/api",
"containerimage.digest": "sha256:abc123..."
},
"web": {
"image.name": "my-registry/web",
"containerimage.digest": "sha256:def456..."
}
}
Run:
docker run --rm -v "$PWD":/workspace compose-tag docker-compose.yml meta.json tags.env
Output tags.env:
API_IMAGE=registry.example.com/api:latest@sha256:abc123...
WEB_IMAGE=registry.example.com/web:latest@sha256:def456...
The db service is ignored because its image doesn't use a ${VAR} reference.
NOTE: LATEST IS IGNORED WHEN DIGEST IS PRESENT AND THE IMAGE PULLED IS THE HASH ONE.
Content type
Image
Digest
sha256:6050d5de6…
Size
8.2 MB
Last updated
6 months ago
docker pull jvitor83/compose-tag:1.0.0