A MySQL database containerization with initialization scripts and data persistence.
- Docker installed on your system
- Docker Compose installed on your system
#. Start the container
- docker-compose up -d
- Verify container is running
- docker ps
- Connect to MySQL mysql -h localhost -P 3306 -u user -p
- Database: mydb
- Username: user
- Password: password
- Root Password: rootpassword
- MySQL Port: 3306
- Defines MySQL service
- Sets up port mapping
- Configures data persistence
- Manages container restart policy
- Creates users table
- Inserts sample data
- Runs automatically on container creation
Start containers:
- docker-compose up -d
Stop containers:
- docker-compose down
View logs:
- docker-compose logs
Access MySQL shell:
- docker exec -it mysql-docker-db-1 mysql -u user -p
Remove everything including volumes:
- docker-compose down -v
Database data is persisted using Docker volumes. The data remains intact even if the container is removed.
- Modify init.sql to change initial database structure
- Update docker-compose.yml for configuration changes
- Rebuild container after changes:
- docker-compose down
- docker-compose up -d --build