Port conflicts with service containers on Docker executor

With many service containers you use on CricleCI it's not possible to change the ports for the container during the job run time. We bind container ports to localhost automatically, and this can be an issue when multiple service containers require the same port. Such as two postgres databases. Consider the example below:

version: 2
jobs:
  build:
    # The primary container is an instance of the first image listed.
    docker:
      - image: circleci/node:4.8.2-jessie
      - image: postgres:11-alpine-ram
      - image: postgres:11-alpine-ram

Both postgres service images will attempt to bind to localhost:5432 and cause an error. You can prevent this by providing a name to your image which will be used as a hostname to bind the image ports to.

  docker:
    - image: circleci/node:4.8.2-jessie
    - image: postgres:11-alpine-ram
    - image: postgres:11-alpine-ram
        name: postgres2

Providing the name parameter will allow the second container to be accessed from postgres2:5432 and the first postgres container from localhost:5432

Further reading:
https://circleci.com/docs/2.0/configuration-reference/#docker

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.