How to use subdomain as app_host with docker-compose?

  capybara, docker, docker-compose

I am trying to setup docker-compose with subdomains. So that I could execute specs on different app_host.
Currently my docker-compose looks as follow:

version: '3'

services:
  webapp:
    container_name: webapp
    depends_on:
      - postgres
      - elasticsearch
      - redis
    build: .
    volumes:
      - .:/webapp
    entrypoint: sh /webapp/setup.sh
    ports:
      - "3000:3000"
    environment:
      - REDISTOGOURL=redis://redis:6379
      - ELASTICSEARCH_URL=http://elasticsearch:9200

  postgres:
    container_name: postgres
    image: postgres:9.5.17
    ports:
      - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql
    environment:
      - POSTGRES_PASSWORD=test
      - POSTGRES_USER=test
      - POSTGRES_DB=test_development

  redis:
    container_name: redis
    image: redis:5.0.5-alpine
    command: ['redis-server', '--appendonly', 'yes']
    hostname: redis
    ports:
      - "6379:6379"
    volumes:
      - redis:/data

  sidekiq:
    build: .
    command: bundle exec sidekiq
    volumes:
      - .:/webapp
    depends_on:
      - postgres
      - redis
    environment:
      - REDISTOGOURL=redis://redis:6379

  elasticsearch:
    image: elasticsearch:6.8.0
    container_name: elasticsearch
    ports:
      - "9200:9200"
    depends_on:
      - postgres
    volumes:
      - esdata:/usr/share/elasticsearch/data
    ulimits:
      nofile:
        soft: 65536
        hard: 65536

  selenium:
    image: selenium/standalone-chrome-debug
    ports:
      - "4444:4444"

volumes:
  redis:
  postgres:
  esdata:

networks:
  new:

And when adding Capybara.app_host = "http://webapp" the spec works fine. However on adding networks to webapp service, the docker-compose up command fails with nc bad address: 'postgres'.

Added aliases:

networks:
      new:
        aliases:
          - www.test.com.in.lvh.me
          - www.test1.com.np.lvh.me

Is there a way I could set aliases for webapp host, so that I could use Capybara.app_host = “www.test.com.in.lvh.me” and it points out to webapp services?

Source: StackOverflow

LEAVE A COMMENT