2

I am getting the following error during the "test_image" step when running tests against docker images in my gitlab CI pipeline. I cannot reproduce it locally, it only occurs on the gitlab runner box. Any ideas?

The container name "/common_run_1" is already in use by container

image: docker:latest

stages:
  - build
  - test
  - release

before_script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN myregistry.gitlab

build_image:
  stage: build
  script:
    - docker build --pull -t $CONTAINER_TEST_IMAGE .
    - docker-compose up -d --build
    - docker push $CONTAINER_TEST_IMAGE

pylint:
  stage: test
  script:
    - docker pull $CONTAINER_TEST_IMAGE
    - docker-compose run common pylint common

test_image:
  stage: test
  script:
    - docker pull $CONTAINER_TEST_IMAGE
    - docker-compose run common nosetests common

push_master_image:
  stage: release
  script:
    - docker pull $CONTAINER_TEST_IMAGE
    - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_MASTER_IMAGE
    - docker push $CONTAINER_MASTER_IMAGE
  only:
    - master

push_prod_image:
  stage: release
  script:
    - docker pull $CONTAINER_TEST_IMAGE
    - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_PROD_IMAGE
    - docker push $CONTAINER_PROD_IMAGE
  only:
    - prod

Update: There are multiple suggestions to simply use "docker-compose down" or "docker stop". I have done this on my gitlab-runner box (completely cleaned out docker processes, images, volumes, and networks), and re-submitted the pipeline request. In this case, I get the same error in the gitlab pipeline. It makes me think there is a concurrency issue in the "test" stage. Furthermore, if I add a "test2" stage and place the "pylint" script inside of it, the pipeline will succeed, further re-enforcing the idea of a concurrency problem.

1
  • I have updated my answer! Please check! Commented Jul 21, 2017 at 11:43

1 Answer 1

2

Your stage:test is having two docker-compose run and both are running using same container name. You can change this by adding --name test1 in docker-compose run of first test and --name test2 in docker-compose run of second test.

Original Answer

Run docker ps -a and it will list which container names are already being used. This is caused mostly because you have already run the container using docker-compose up and the containers are still up.

Your options are

  1. Run docker-compose down. This should bring down the already running containers. And should most probably solve your error.
  2. If option 1 fails, then you can see which containers are running and stop those containers by running docker stop <container_name>.
Sign up to request clarification or add additional context in comments.

2 Comments

The container name should include the $CI_JOB_ID variable so it will not clash with pipes running for other commits.
It's also a good idea to run docker-compose down at the end of the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.