You are currently viewing How to run MySQL database using Docker-Compose in 3 minutes? – cool example!
Photo by Glenn Case on Unsplash
Could You Please Share This Post? I Appreciate It And Thank YOU! :) Have A Nice Day!
4.8
(1215)

In this article we will focus only on showing how to quickly run MySQL database using Docker-Compose. In short: docker-compose MySQL. Using volumes, we do not lose changes that we make in the database. Changes will still be visible after closing and restarting the container.

Run MySQL database using Docker-Compose

Create file: docker-compose.yml

We create the file docker-compose.yml. Inside the file please put the code below. To create the container we will use the image mysql:7.7.

version: '3'
services:
  mysql-db:
    image: mysql:5.7
    hostname: mysql-db
    container_name: mysql_db
    restart: always
    environment:
      MYSQL_DATABASE: 'bigdataetl'
      MYSQL_USER: 'user_bigdataetl'
      MYSQL_PASSWORD: 'password_bigdataetl'
      MYSQL_ROOT_PASSWORD: 'password_for_root_user'
    ports:
      - '3306:3306'
    volumes:
      - my-db-volume:/var/lib/mysql
volumes:
  my-db-volume:

We save the file and then we just need to run the following command being in the directory where we have the file previously created by us YML file.

docker-compose up -d

After a few moments, the container will be created, up and running. We can check the status of our container.

docker-compose ps

  Name               Command             State                 Ports              
----------------------------------------------------------------------------------
mysql_db   docker-entrypoint.sh mysqld   Up      0.0.0.0:3306->3306/tcp, 33060/tcp

Let’s check the connection. I will use DBeaver. As you can see the connection works. We are able to use our MySQL database using docker and compose

How to run MySQL database using Docker-Compose in 3 minutes? - cool example!
docker-compose MySQL
Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

BigData-ETL: image 7YOU MIGHT ALSO LIKE

How useful was this post?

Click on a star to rate it!

Average rating 4.8 / 5. Vote count: 1215

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?