S
S
sergei19932019-07-05 13:41:53
Docker
sergei1993, 2019-07-05 13:41:53

How to connect multiple docker-compose projects?

There are two docker-compose projects:

First:

version: '3'
services:

  postgresql:
    image: postgres:alpine
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=wls
      - POSTGRES_USER=wls
      - POSTGRES_PASSWORD=wls
    volumes:
      - db-volume:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql

  redis:
    image: redis:4.0-alpine
    ports:
      - 6379:6379
  app:
    build: .
    command: /bin/sh -c "bundle install && bundle exec rake db:schema:load && rake db:seed && rm -f /app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0' && tail -f /dev/null"
    volumes:
      - ../../wls:/app
      - bundle1-volume:/usr/local/bundle
    ports:
      - 3086:3000
      - 8125:8125
    env_file:
      - ../.env.main
    networks:
      - nginx_proxy
      - default
    depends_on:
      - postgresql
      - redis

    tty: true
    stdin_open: true

  sidekiq:
    build: .
    command: /bin/sh -c "bundle install && bundle exec sidekiq"
    volumes:
      - ../../wls:/app
      - bundle2-volume:/usr/local/bundle
    ports:
      - 3087:3000
    env_file:
      - ../.env.main
    networks:
      - nginx_proxy
      - default
    depends_on:
      - postgresql
      - redis
      - app
    tty: true
    stdin_open: true

networks:
  nginx_proxy:
    driver: bridge
    ipam:
      driver: default
      config:
       - subnet: 10.5.0.0/16

And the second one:


version: '3'
services:

  postgresql:
    image: postgres:alpine
    ports:
      - 5434:5432
    env_file:
      - .env.database
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
      - db-volume:/var/lib/postgresql/data

  redis:
    image: redis:4.0-alpine
    ports:
      - 6381:6379
  solr:
    build: .
    command: /bin/sh -c "bundle install && bundle exec rake sunspot:solr:start && tail -f /dev/null"
    volumes:
      - ../../wls:/app
      - bundle3-volume:/usr/local/bundle
    ports:
      - 3088:3000
      - 8982:8982
    env_file:
      - ../.env.main
    networks:
      nginx_proxy:
        ipv4_address: 10.5.0.6
    depends_on:
      - postgresql
      - redis
      - app
    tty: true
    stdin_open: true

  app:
    build: .
    command: /bin/sh -c "bundle install && bundle exec thin start -C config/thin.yml"
    volumes:
      - ../../bequeue:/app
      - bundle-volume:/usr/local/bundle
    ports:
      - 3002:3000
    depends_on:
      - redis
    networks:
      - nginx_proxy
      - default
    env_file:
      - ../.env.main
    tty: true
    stdin_open: true

  worker:
    build: .
    command: /bin/sh -c "bundle install && RACK_ENV=production rake db:schema_load && RACK_ENV=production bundle exec sidekiq -r ./lib/run_queue.rb -c 20"
    volumes:
      - ../../gateway:/app
      - bundle-volume:/usr/local/bundle
    depends_on:
      - redis
      - postgresql
    ports:
      - 9219:9219
    networks:
      - nginx_proxy
      - default
    env_file:
      - ../.env.main
    tty: true
    stdin_open: true

volumes:
  bundle-volume:
  db-volume:
  node-modules-volume:

networks:
  nginx_proxy:
    external: true


Question:

I need the first project to have a static ip address, and I did it.

But the catch is that containers from another project now do not see the first project.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question