Adding a database service using Docker Compose

To resolve the application error we currently have when running the release image, we need to run a database that the application can connect to, and ensure the application is configured to use the database.

We can achieve this using Docker Compose by adding a new service called db, which is based on the official MySQL server container:

version: '2.4'services:  test:    build:      context: .      dockerfile: Dockerfile      target: test  release:    build:      context: .      dockerfile: Dockerfile    ports:      - 8000:8000    command:      - uwsgi      - --http=0.0.0.0:8000      - --module=todobackend.wsgi      - --master  db:    image: mysql:5.7    environment:      MYSQL_DATABASE: todobackend      MYSQL_USER: todo      MYSQL_PASSWORD: password MYSQL_ROOT_PASSWORD: password ...

Get Docker on Amazon Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.