Gitlab Runners - Container Conflict when processing more than 1 job at the same time

We have a situation where we see the following error when trying to run two simultaneous jobs on the same AWS EC2 Gitlab runner.

ERROR: for blah Cannot create container for service blah: Conflict. The container name “/blah” is already in use by container “blah”. You have to remove (or rename) that container to be able to reuse that name.

Now i get why this is happening from a Docker perspective but is there a way around this issue when running the same job, the job runs tests on code changes. So multiple jobs could be running at the same time.

This behaviour is not seen on the shared runners, only on self managed runners in an EC2 ASG.

HI @adam2798 :wave:, welcome to the GitLab Community Forum! :tada:

The error message you’re seeing is Docker’s way of telling you that a container with the name “blah” already exists. When you try to run another job with the same container name, Docker throws this error because it can’t create a new container with the same name.

Do you see this error when running any/all jobs simultaneously, or only CI jobs that use services?

Assuming you encounter this when using services, here are some possible workarounds:

  1. Use unique names for each job: One way to avoid this issue is to ensure that each job uses a unique container name. This can be achieved by appending a unique identifier (like the CI_JOB_ID) to the container name. This way, each job will have its own unique container, and you won’t run into any conflicts.
  - name: blah:${CI_JOB_ID}` 
  1. Use Docker’s --rm option: Another way to avoid this issue is to use Docker’s --rm option, which automatically removes the container when it exits. This ensures that the container name is freed up as soon as the job is done, making it available for the next job.

yamlCopy code

  - name: blah
    command: ["--rm"]` 

If you encounter this even when not using services - what value do you have configured for concurrent in your Runner’s config.toml? If it’s only set to 1, you’ll need to increase it to allow for running multiple jobs concurrently.

1 Like

Thanks i think i have a workaround on this.

1 Like