3

Is it possible to programmatically add labels to all docker images built on a machine?

An example might be adding a label of: build-agent: docker-build-01

The specific use case is adding job details using jenkins.

Thanks.

Graeme
  • 375

1 Answers1

6

You can't do this at the docker engine level, but since you're building with Jenkins, you can do it within your pipeline script. In the build command, you can add any labels you want to your image, e.g.

docker build --label "build-agent=${NODE_NAME}" -t $image_name .

The --label option allows you to set any labels you want on your image, even without a field in the Dockerfile for that label. And ${NODE_NAME} is defined by Jenkins in the environment.

BMitch
  • 2,302
  • 11
  • 15