Reputation: 61874
From the official Docker Compose build doc:
If you specify image as well as build, then Compose names the built image with the webapp and optional tag specified in image:
Example:
build:
...
image: myapp:tag
but I would like to replace tag
with the output of git rev-parse --short HEAD
.
Ideally I need something like:
image: myapp:$(git rev-parse --short HEAD)
Upvotes: 11
Views: 10733
Reputation: 1324957
The build ARGS
section illustrates jonrsharpe's comment
You need to set an environment variable first, and declare the ARGS in your docker-compose.yml
ARG commit
...
image: "myapp:${commit}"
See "variable substitution" and also The “env_file
” configuration option
Your configuration options can contain environment variables.
Compose uses the variable values from the shell environment in whichdocker-compose
is run.
Any hope of running a command directly in the docker-compose.yml
file was ruled out with docker/compose
issue 4081.
Upvotes: 6