Docker Compose: How to run MySQL database?

Docker Compose: How to run MySQL database?
Photo by Glenn Case on Unsplash

In this article we will focus only on showing how to quickly launch the MySQL database in a container.

Using volumes, we do not lose changes that we make in the database. Changes will still be visible after closing and restarting the container.

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'
    image: mysql:5.7
    hostname: mysql-db
    container_name: mysql_db
    restart: always
      MYSQL_DATABASE: 'bigdataetl'
      MYSQL_USER: 'user_bigdataetl'
      MYSQL_PASSWORD: 'password_bigdataetl'
      MYSQL_ROOT_PASSWORD: 'password_for_root_user'
      - '3306:3306'
      - my-db-volume:/var/lib/mysql

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 docker-compose.yml.

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 mysqld   Up>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 docker-compose.

If you enjoyed this post please add the comment below or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments