This repository contains a Docker Compose configuration for setting up a MySQL database container with environment variables stored in a .env
file. The database persists data using Docker volumes to ensure that data remains intact even after container recreation.
Ensure you have the following installed on your system:
git clone <repository-url>
cd <repository-directory>
Create a .env
file in the project root directory and add the following environment variables:
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_USER=your_custom_user
MYSQL_PASSWORD=your_custom_password
MYSQL_DATABASE=your_database_name
Replace your_root_password
, your_custom_user
, your_custom_password
, and your_database_name
with your desired values.
Run the following command to start the MySQL container:
docker-compose up -d
This command will start the container in detached mode.
To check if the MySQL container is running, use:
docker ps
To view logs, run:
docker-compose logs db
docker exec -it <container_id> mysql -u$MYSQL_USER -p$MYSQL_PASSWORD
Replace <container_id>
with the actual container ID, which can be found using docker ps
.
- Host:
localhost
- Port:
3306
- User:
$MYSQL_USER
(as per.env
file) - Password:
$MYSQL_PASSWORD
(as per.env
file) - Database:
$MYSQL_DATABASE
To stop the MySQL container, use:
docker-compose down
This will remove the container but keep the data in the volume.
If you want to remove all persistent data, run:
docker volume rm <volume_name>
Replace <volume_name>
with db_data
if using the provided docker-compose.yml
.
To contribute:
- Make necessary changes.
- Commit the changes and push to a new branch.
- Create a Merge Request (MR) to the main branch.
This project is open-source and available under the MIT License.
Hardik Kumar SIngh