Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created April 2, 2020 00:34
Show Gist options
  • Save BetterProgramming/1abbc0d891fa7d3e2b758b5bbf90188a to your computer and use it in GitHub Desktop.
Save BetterProgramming/1abbc0d891fa7d3e2b758b5bbf90188a to your computer and use it in GitHub Desktop.
services:
db:
image: mongo:latest
ports:
- "27017:27017"
container_name: db
volumes: shared_database:/data/db
vc_db:
image: mongo:latest
volumes: shared_database:/data/db
volumes:
shared_database;
@sushant2517
Copy link

sushant2517 commented May 11, 2024

I was referring to your article here - https://betterprogramming.pub/persistent-databases-using-dockers-volumes-and-mongodb-9ac284c25b39
I tried to create the docker compose the way you have instructed. But when I run it, it creates the instances as defined, but always shuts down my mongodb runtime instance. It still keeps the vc instance running. My application instance is running as well.
Do you think this approach is still valid? Any other ways to handle this?
Thanks, Sushant

Here is my setup: Docker on Windows10 with Linux container
Here is the docker compose:

services: # Services to deploy
  mongodb:
    image: mongo
    container_name: mongodb
    networks:
      - prop_nw
    ports:
      - '27017:27017'
    volumes:
      - prop-db-volume:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: test
  
  mongodb_vc:
    image: mongo
    container_name: mongodb-vc
    volumes:
      - prop-db-volume:/data/db

volumes: 
  prop-db-volume:
networks:
  prop_nw:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment