How to deploy MySQL database using Docker Compose?
To deploy a MySQL database using docker-compose, follow these steps:
- First, make sure you have Docker and docker-compose installed. If not, please install them first.
- Create a new folder to store your docker-compose.yml file.
- Create a file named docker-compose.yml in the folder and input the following content into the file:
version: '3.7'
services:
mysql:
image: mysql:latest
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: your_password
volumes:
- ./data:/var/lib/mysql
- Replace the “your_password” above with the MySQL root password you want to set.
- Replace the above ./data with the path where you want to store the MySQL data locally.
- Save and close the docker-compose.yml file.
- Open the terminal or command line interface, and navigate to the folder containing the docker-compose.yml file.
- Run the following command to start the MySQL database container:
docker-compose up -d
- Wait for a period of time until the MySQL container is fully started. You can use the following command to check the status of the container:
docker-compose ps
- local computer or local server
- 3306 – Three thousand three hundred and six
This way, you can deploy a MySQL database using docker-compose.