docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.28k stars 548 forks source link

.Config.Labels vs .ContainerConfig.Labels #887

Closed alex-old-user closed 10 months ago

alex-old-user commented 1 year ago

Hello, I'm not sure whether it's a bug or by design. When I do sth simple as

      - uses: docker/build-push-action@v4
        with:
          push: true
          labels: |
            foo=bar

and then check the image with docker inspect, .Config.Labels is populated with the label, but .ContainerConfig.Labels is set to null. Setting the label in Dockerfile has the same result. Is this the expected behavior for the action? Is there a way to set .ContainerConfig.Labels?

thanks

crazy-max commented 10 months ago

This is expected.

When you set labels using the LABEL instruction in the Dockerfile or using the docker label command or --label with build command, the labels are stored in the image's configuration (.Config.Labels). These labels provide metadata about the image itself.

However, when a container is created from the image, the runtime configuration of the container is stored in the .ContainerConfig field. This includes information about the running container, and it does not include the labels from the image. Therefore, .ContainerConfig.Labels remains null.

More info: