Port conflicts with service containers on Docker executor

With many service containers you use on CircleCI 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

この記事は役に立ちましたか?
2人中0人がこの記事が役に立ったと言っています

コメント

0件のコメント

サインインしてコメントを残してください。