docker,

Overwrite image tags with Docker Compose

Jun 28, 2023 · 1 min read · Post a comment

To overwrite the image tag specified in the Docker Compose file and use a different tag from the CLI, you can use environment variables or override the service configuration.

Prerequisites

  • Docker
  • Docker Compose

Solution

Given the following Docker Compose example:

version: '3'

services:
  my-service:
    image: my-image:${TAG:-dev}
    # ...

If the TAG env var is not set, it falls back to dev. This allows you to override the tag using the TAG environment variable from the command line e.g. TAG=my-branch-tag-1 docker-compose up.

Conclusion

In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.