How to deploy MySQL database using Docker Compose?

To deploy a MySQL database using docker-compose, follow these steps:

  1. First, make sure you have Docker and docker-compose installed. If not, please install them first.
  2. Create a new folder to store your docker-compose.yml file.
  3. 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
  1. Replace the “your_password” above with the MySQL root password you want to set.
  2. Replace the above ./data with the path where you want to store the MySQL data locally.
  3. Save and close the docker-compose.yml file.
  4. Open the terminal or command line interface, and navigate to the folder containing the docker-compose.yml file.
  5. Run the following command to start the MySQL database container:
docker-compose up -d
  1. 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
  1. local computer or local server
  2. 3306 – Three thousand three hundred and six

This way, you can deploy a MySQL database using docker-compose.

bannerAds