This project uses Docker Compose to run a MySQL 8 database container locally.
- Docker installed on your system
- Docker Compose installed (included in Docker Desktop)
Run the following command to start the container:
docker compose up -dThis will start a MySQL container in detached mode.
To enter the MySQL container shell, use:
docker exec -it mysql_local_4406 bashTo directly access MySQL inside the container:
docker exec -it mysql_local_4406 mysql -u myuser -pEnter the password (mypassword) when prompted.
To import a database dump from the host machine:
docker cp yourfile.sql mysql_local_4406:/yourfile.sql
docker exec -it mysql_local_4406 mysql -u myuser -p mydatabase < /yourfile.sqlTo stop the container without deleting data:
docker compose downTo remove the container and its data:
docker compose down -vThe MySQL database data is stored in a Docker volume to persist even after restarting the container:
volumes:
- mysql_data_jlr_db:/var/lib/mysql
Modify docker-compose.yml to change database credentials:
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: mydatabase
MYSQL_USER: myuser
MYSQL_PASSWORD: mypassword-
Check running containers:
docker ps
-
View logs:
docker logs mysql_local_4406
-
Restart the container:
docker restart mysql_local_4406
Enjoy using MySQL with Docker! 🚀