How to solve Docker compose error ".labels array items must be unique"?
Emmanuel Gautier / January 21, 2024
1 min read
If you have the validating docker-compose.dev.yml: services.xxx.labels array items must be unique
error showing up when you are trying to run your docker compose, you are at the right place.
Let's consider a scenario where you have separate Docker Compose files for production and development environments. The production compose file (docker-compose.prod.yml
) might look like this:
version: '3'
services:
web:
image: production-image:latest
ports:
- "80:80"
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefiknet"
- "traefik.http.routers.yourservice.rule=Host(`service.example.com`)"
- "traefik.http.routers.yourservice.service=yourservice"
- "traefik.http.routers.yourservice.entrypoints=http"
- "traefik.http.services.yourservice.loadbalancer.server.port=4455"
- "traefik.http.services.yourservice.loadbalancer.passHostHeader=true"
And the development compose file (docker-compose.dev.yml
) may look similar, with adjustments for the development environment:
version: '3'
services:
web:
image: development-image:latest
ports:
- "8080:80"
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefiknet"
- "traefik.http.routers.yourservice.rule=Host(`service.example.local`)"
- "traefik.http.routers.yourservice.service=yourservice"
- "traefik.http.routers.yourservice.entrypoints=http"
- "traefik.http.services.yourservice.loadbalancer.server.port=4455"
- "traefik.http.services.yourservice.loadbalancer.passHostHeader=true"
Unique Labels Requirement
The error "Docker Compose .labels array items must be unique" arises when Docker compose labels are duplicated between Docker Compose files. In our example, if both production and development files share the same labels, this error will occur.
Solution
Remove from development docker compose file any labels that are already present in the production Docker Compose file (docker-compose.prod.yml). Example:
version: '3'
services:
web:
image: development-image:latest
ports:
- "8080:80"
labels:
- "traefik.http.routers.yourservice.rule=Host(`service.example.local`)"
Consulting
If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.
Related Posts
How to fix DNS Internal Resolution inside the Nginx docker container
Sometimes, errors with Docker and some containers can become cryptic when it is about networking. Today, it was Nginx that was not able to reach another container.
MySQL Docker Image for Mac ARM M1
MySQL official Docker image is not available for Apple ARM-based M1 and M2 CPUs. But there is some options to use mysql image on Mac and more globally on ARMv8 microarchitecture.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
Featured Posts
Introducing new blog about OAuth, OpenID Connect, and IAM Solutions
I'm excited to announce the launch of a new blog named CerberAuth, where I'll be exploring the world of OAuth, OpenID Connect, and IAM solutions for modern security.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
How to enable Python type checking in VSCode
Python now has support for type hints. In this article, we will see how to enable better IntelliSense and type checking analysis in VSCode.