concept example-4 in category docker

appears as: example-4
Bootstrapping Microservices with Docker, Kubernetes and Terraform

This is an excerpt from Manning's book Bootstrapping Microservices with Docker, Kubernetes and Terraform.

Figure 7.6. Click the Enable button to enable Bitbucket Pipelines
Listing 8.11 - Loading the db fixtures REST API with Docker Compose (extract from chapter-8/example-3/docker-compose.yaml)
version: '3'
services:
 
  db: #A
    image: mongo:4.2.0
    container_name: db
    ports:
      - "27017:27017"
    expose:
      - "27017"
    restart: always #A
 
  db-fixture-rest-api: #B
    image: db-fixture-rest-api
    build:
      context: ./db-fixture-rest-api
      dockerfile: Dockerfile
    container_name: db-fixture-rest-api
    ports:
     - "9000:80"
    environment:
     - PORT=80
     - DBHOST=mongodb://db:27017
     - FIXTURES_DIR=fixtures
    volumes:
     - ./fixtures:/usr/src/app/fixtures:z
    depends_on:
      - db
    restart: always #B
 
    #C

Just be careful that you never run this test against a production database. Loading a database fixture wipes out the relevant database collections and you never want to lose production data. You shouldn’t be able to do this in production anyway because you would never ever run the database fixtures REST API in production. That’s giving us the capability to load database fixtures, but we only need it for development and testing environments. Running it in a production environment will give external access to your database which is a recipe for disaster.