Docker compose and concurrent integration testing

Edit: sorry, I was mistaken about the first part of this question.

So I have a docker-compose.yaml that’s working fine when ran synchronously:

  • Cannot access app in Docker container from outside
  • Symfony logs to stdout inside Docker container
  • Docker on Amazon Linux AMI
  • OSX boot2docker trouble connecting to docker daemon
  • What is the docker command to run jenkins container in windows
  • How can I run a complex docker command from host machine that runs in the docker host?
  • server:
      build: .
      dockerfile: "./docker/integration_tests/server/Dockerfile"
      links:
        - mongo
      environment:
        - "MONGO_URI=mongodb://mongo:27017/company"
    
    mongo:
      image: 'mongo:3.2.6'
      ports:
        - "27017"
    

    When launched with this command: docker-compose build && docker-compose up --abort-on-container-exit

    However when I launch two or three jobs to test if it works in parallel (this is in Jenkins using pipelines, so they have different directories) I’m seeing this on job A:

    Successfully built 7b23b3a7b823
    + docker-compose up --abort-on-container-exit
    Creating companyservercicd3_mongo_1
    
    ERROR: for mongo  Cannot start service mongo: driver failed programming external connectivity on endpoint companyservercicd3_mongo_1 (422826f73ce76526e4072f72a2b44467f9080e79a24d37d1fe2bba903854a698): Bind for 0.0.0.0:27017 failed: port is already allocated
    Encountered errors while bringing up the project.
    

    And this on job B:

    Successfully built 80aa795867eb
    + docker-compose up --abort-on-container-exit
    Creating companyservercicd4_mongo_1
    
    ERROR: for mongo  Cannot start service mongo: driver failed programming external connectivity on endpoint companyservercicd4_mongo_1 (1591f2847e6c0d81f2c530874201ea912fa59ea35bfa27e5b25d7843e06da6b5): Bind for 0.0.0.0:27017 failed: port is already allocated
    Encountered errors while bringing up the project.
    

    The docs say this about the ports config option:

    Expose ports. Either specify both ports (HOST:CONTAINER), or just the
    container port (a random host port will be chosen).

    I must be misunderstanding something because I thought 27017 would be within a container, and that each job would have its own container. What am I doing wrong here?

    Another somewhat related question – this works well in Jenkins because Jenkins is creating a new directory per job so there are no name conflicts, but would there be a way to make this bulletproof by passing in an option that would let each run have its own name? Another user recommended doing this as a workaround:

    `docker-compose run --rm --no-deps --name `uuidgen` ...`
    

    But that would require me to rework my docker-compose.yml and convert the up command into the equivalent build/create/start/attach

  • How to run or use multiple registry mirror?
  • docker restart on cascade
  • Creating a docker image from an existing enviornment
  • What are the differences between sharing a dockerfile on git and sharing a docker container?
  • Can we create volumes inside docker container
  • How does network communication between 2 Docker Containers work?
  • One Solution collect form web for “Docker compose and concurrent integration testing”

    So I guess this was a false alarm – having one number for each list item under ports did fix the port conflicts I was experiencing.

    I fixed the names not being unique enough (and therefore not as resilient to concurrency) by invoking docker-compose build and up like so: COMPOSE_ID=uuidgen_; docker-compose -p $COMPOSE_ID build && docker-compose -p $COMPOSE_ID up --abort-on-container-exit, with the command that actually runs the test living in my docker-compose.yml

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.