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:
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
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:
_; 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