Giter Club home page Giter Club logo

localmongo's Introduction

Localmongo

Local mongo replicaset running mongo:4.2-bionic for development using docker-compose.

Setup

Simply run:

docker-compose up

This should bring up 3 containers of mongodb, running a replicaset called rs0.

Application

In your main application, you need to adjust your docker-compose in order for your application to be able to connect to the mongo containers. Use the below template of docker-compose.yml:

version: "3"
services:
  app:
    build: .
    networks:
      - default
      - localmongo
    external_links:
      - localmongo1:mongo1
      - localmongo2:mongo2
      - localmongo3:mongo3
networks:
  localmongo:
    external:
      name: localmongo_default

Troubleshooting

Assuming you clone this repo into a folder called localmongo, upon running docker-compose, docker will create a network called localmongo_default. You can view this by running docker network ls, and also by inspecting docker inspect localmongo1.

In the application's docker-compose.yml, we are specifying that the app must join 2 networks: the default one, as well as localmongo network, which is declared at the end of the file, pointing to an external network localmongo_default.

To troubleshoot connectivity issues, do docker exec -it <appContainerID> bash into your application container and look at cat /etc/hosts. You should see 2 entries for the container, one per network. You should be able to do ping mongo1.

If it does not work, do docker inspect <appContainerID> and proceed from there. To clean up networks, use with care: docker network prune

Checkout the documentation of docker-compose networking.

Credits

Kira Layto for their Stack Overflow code snippet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.