Build and Run Laravel 7 in Docker Part 4 - MySQL

Build and Run Laravel 7 in Docker Part 4 - MySQL

Add the Database

We want to persist this container allowing us to stop and start it without losing data. We can achieve this with a volume.

Open your docker-compose and under the web block add the following:

database:
  image: mysql:5.7
  volumes:
    - dbdata:/var/lib/mysql
  environment:
    MYSQL_DATABASE: ${DB_DATABASE}
    MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    MYSQL_PASSWORD: ${DB_PASSWORD}
  ports:
      - "33061:3306"

 

Part 5 - Final Steps

Categories: Posts