version: '2'
services:
  teddy_postgres:
    image: postgres:9.5
    container_name: teddy_postgres
    environment:
      POSTGRES_USER: teddy
      POSTGRES_PASSWORD: teddy
    ports:
      - :5432:5432

  #################### Base  ####################

  base: &base
    build: .
    env_file: .env
    links:
      - teddy_postgres:postgres
    volumes:
      - .:/home/app/teddy
      - teddy_gems_2_4_0:/usr/local/bundle

  #################### CONTAINERS ####################

  teddy_app:
    <<: *base
    container_name: teddy_app
    command: /bin/bash bin/server.sh
    ports:
      - :3000:3000
    environment:
      - RAILS_ENV=development

  teddy_tests:
    <<: *base
    container_name: teddy_tests
    command: /bin/bash bin/tests.sh
    environment:
      - RAILS_ENV=test

networks:
  default:
    external:
      name: teddy

volumes:
  teddy_gems_2_4_0:

version: '2'
services:
  teddy_postgres:
    image: postgres:9.5
    container_name: teddy_postgres
    environment:
      POSTGRES_USER: teddy
      POSTGRES_PASSWORD: teddy
    ports:
      - :5432:5432

  #################### Base  ####################

  base: &base
    build: .
    env_file: .env
    links:
      - teddy_postgres:postgres
    volumes:
      - .:/home/app/teddy
      - teddy_gems_2_4_0:/usr/local/bundle

  #################### CONTAINERS ####################

  teddy_app:
    <<: *base
    container_name: teddy_app
    command: /bin/bash bin/server.sh
    ports:
      - :3000:3000
    environment:
      - RAILS_ENV=development

  teddy_tests:
    <<: *base
    container_name: teddy_tests
    command: /bin/bash bin/tests.sh
    environment:
      - RAILS_ENV=test

  teddy_root:
    <<: *base
    user: root
    container_name: teddy_root
    command: /bin/bash

networks:
  default:
    external:
      name: teddy

volumes:
  teddy_gems_2_4_0:

Add container with root access
Add container with root access
