How to get Docker IP address on Travis CI?

I have a Rails repository on Travis. It has a docker-compose.yml file:

postgres:
  image: postgres
  ports:
    - "5433:5432"
  environment:
    - POSTGRES_USER=calories
    - POSTGRES_PASSWORD=secretpassword

(I had to use 5433 as a host port because 5432 gave me an error: Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use)

And travis.yml:

sudo: required

services:
  - docker
language: ruby
cache: bundler
before_install:
  # Install docker-compose
  - curl -L https://github.com/docker/compose/releases/download/1.4.0/docker-compose-`uname -s`-`uname -m` > docker-compose
  - chmod +x docker-compose
  - sudo mv docker-compose /usr/local/bin
  # TODO: Remove this temporary fix when it safe to:
  # https://github.com/travis-ci/travis-ci/issues/4778
  - sudo iptables -N DOCKER || true
  - sleep 10
  - docker-compose up -d
before_script:
  - bundle exec rake db:setup
script:
  - bundle exec rspec spec
after_script:
  - docker-compose stop
  - docker-compose rm -f

I am trying to figure out what to add to my database. Therefore, my tests can work on Travis CI. In other environments, I can do:

adapter: postgresql
encoding: unicode
host:  <%= `docker-machine ip default` %>
port: 5433
username: calories
password: secretpassword
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5

But, unfortunately, this does not work on Travis, because on Travis not docker-machine. I get an error message:docker-machine: command not found

How can I get the Docker IP address on Travis?

+4
source share
2 answers

, , , IP- , IP- . docker-machine IP-, - VM .

, localhost host.

:

+2

, , IP- ,

export HOST_IP_ADDRESS="$(/sbin/ip route|awk '/default/ { print $3 }')"

. script, : $HOST_IP_ADDRESS.

, , , , . , , Travis Postgres ( , IP- ).

, , , , . , , , , ..

: localhost , 127.0.0.1?

0

Source: https://habr.com/ru/post/1611190/


All Articles