3
votes

This is the docker-compose.yml file in MEAN.js. Could anyone can explain why the entrypoint is set to /bin/true for web-data and db-data? Is this necessary? and what would happen if I remove it? Many thanks.

version: '2'
services:
  web:
    restart: always
    build: .
    container_name: meanjs
    ports:
     - "3000:3000"
     - "5858:5858"
     - "8080:8080"
     - "35729:35729"
    environment:
     - NODE_ENV=development
     - DB_1_PORT_27017_TCP_ADDR=db
    depends_on:
     - db
    volumes_from:
     - web-data
  web-data:
    build: .
    entrypoint: /bin/true
    volumes:
     - ./:/opt/mean.js
     - /opt/mean.js/node_modules
     - /opt/mean.js/public
     - /opt/mean.js/uploads
  db:
    image: mongo:3.2
    restart: always
    ports:
     - "27017:27017"
    volumes_from:
      - db-data
  db-data:
    image: mongo:3.2
    volumes:
      - /data/db
      - /var/lib/mongodb
      - /var/log/mongodb
    entrypoint: /bin/true

1

1 Answers

4
votes

This is an older version of Docker-compose. The reason for doing this is to start a container, which creates volumes and then exits.

So the below starts a container and exists

  db-data:
    image: mongo:3.2
    volumes:
      - /data/db
      - /var/lib/mongodb
      - /var/log/mongodb
    entrypoint: /bin/true

Inside that container these volumes path get created.

      - /data/db
      - /var/lib/mongodb
      - /var/log/mongodb

Then mongo uses volumes_from to store data in this container

  db:
    image: mongo:3.2
    restart: always
    ports:
     - "27017:27017"
    volumes_from:
      - db-data

volumes_from is no deprecated in Compose 3.X and should not be used. Instead either you should use named of anonymous volumes.

So the compose would change to something like below

Anonymous volumes

version: '3.3'
....
  db:
    image: mongo:3.2
    restart: always
    ports:
     - "27017:27017"
    volumes:
      - /data/db
      - /var/lib/mongodb
      - /var/log/mongodb

Named volumes

version: '3.3'
....
  db:
    image: mongo:3.2
    restart: always
    ports:
     - "27017:27017"
    volumes:
      - mongodata:/data/db
      - mongodata:/var/lib/mongodb
      - mongodata:/var/log/mongodb
volumes:
  mongodata: {}