Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add database feature #3

Closed
litan1106 opened this issue Oct 18, 2019 · 2 comments
Closed

Add database feature #3

litan1106 opened this issue Oct 18, 2019 · 2 comments

Comments

@litan1106
Copy link

Real world app always have a database.

@hacfi
Copy link

hacfi commented Oct 18, 2019

As you copy the docker-compose.yml to your project you can add your database of choice there. For mysql e.g.:

version: '3.4'

services:
  # ...

  db:
    image: mysql:5.7 # or percona or mariadb
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql:rw
    environment:
      MYSQL_DATABASE: "db"
      MYSQL_USER: "user"
      MYSQL_PASSWORD: "password"
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

volumes:
  mysql_data:
    driver: local

and add DATABASE_URL: "mysql://user:password@db:3306/db" to your env vars (see https://github.com/sherifabdlnaby/symdocker/blob/master/docker/.compose/docker-compose.yml#L14).

For postgres you can use something like:

version: '3.4'

services:
  # ...

  db:
    image: postgres:12
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data:rw
    environment:
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
      POSTGRES_DB: "db"

volumes:
  pgdata:
    driver: local

and use "postgres://user:password@db:5432/db" as the DATABASE_URL.

@litan1106
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants