I have set up an php laravel sql platform with docker compose with the following docker compose.yml. I only have one database(with production data) but I also want to test out somethings with dummy data, therefore I need to set up another database without going back and forth. What is the most simple and effective way I can do this. I am using Dbeaver for DB management.
services:
web:
build:
context: .
dockerfile: Dockerfile
container_name: web
working_dir: /var/www/html
volumes:
- ./src:/var/www/html
- ./config/php:/usr/local/etc
ports:
- 8080:80
networks:
- mfund-network
depends_on:
db:
condition: service_healthy
db:
image: mysql:5.7.33
container_name: db
environment:
MYSQL_DATABASE: production
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ALLOW_EMPTY_PASSWORD: yes
volumes:
- dbdata:/var/lib/mysql
ports:
- 3306:3306
networks:
- mfund-network
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h db -P 3306 -u root -p$$MYSQL_ROOT_PASSWORD"]
interval: 5s
timeout: 20s
retries: 30
networks:
my-network:
driver: bridge
volumes:
dbdata:
I have tried creating two database with one connection in Dbeaver with init.sql but I can't seem to switch between the two unless I use docker compose down -v which completely wipes out all the volume and I have to import the production data and set up again. If possible, I don't want to restart the container, I simply want to switch between the databases I will be working on.
-- Create the test database if it doesn't exist
CREATE DATABASE IF NOT EXISTS test;
I want two databases: production and test