Easy way to deploy MySQL 5.7 Docker container in Ubuntu 20.04 for Local development

Hello, this is my 5 min guide on how to run MySQL 5.7 (or any previous).

After installing the fresh Kubuntu 20.04 I discovered that he comes with MySQL v8.

It’s not impossible to downgrade your MySQL 8 to  5.7 and even I made it on 2 machines. You can find how in this article

But I discovered that there is the easiest way! Dockers

You don’t need to be Docker expert to fire the MySQL.

 

First of all, you need Docker installed

sudo apt install docker

 

Next to make your life easier:

sudo apt install docker-compose

 

You can install even Portainer.io Follow their guide. A GUI for easy dockers management.

 

Prepare the folders

Create 2 folders if you want to use the additional extras: one for the additional MySQL config (my.cnf) and one where the data will be stored (if you want) outside the container. I found that the MySQL container comes without any text editor, so is impossible or hard to edit your .ini files. There are some tricks with Dockerfile for adding additional packages in your container but I prefer to take out this my.cnf outside. To do this you have to “map” the internal path to external:

- /home/adk/dockers/mysql57/conf.d/:/etc/mysql/conf.d

and do the same for the database storage place.

Inside the /home/adk/dockers/mysql57/conf.d/ folder create empty my.cnf text file. For test purposes paste this:

[mysqld] 
max_connections=200

`

Create one more folder (change your home folder path). The parameter -p will help you to create the full path and not folder by folder:

mkdir -p /home/adk/dockers/mysql57/db

Next

Create your own .yml file (for example stack.yml).  You can use the standard docker-compose.yml name or a custom one. Paste and edit this simple config

# Use root/example as user/password credentials
version: '3.1'

services:
  db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: example
    expose:
      # Opens port 3306 on the container
      - 3306
    volumes:
      - /home/adk/dockers/mysql57/conf.d/:/etc/mysql/conf.d
      - /home/adk/dockers/mysql57/db:/var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

Note: the indents in the .yml files are very important. So ill provide the code in a text file.

This code will install MySQL 5.7 on your machine + adminer (PHPMyAdmin). Your container will work on port 3306

End

To run and finish the job execute this command:

sudo docker-compose -f stack.yml up
or
sudo docker-compose -f stack.yml start //to freeup the console

You can open the “adminer” at http://localhost:8080/ or use for example Heidi SQL (an amazing tool which you can use even in Linux via wine)

use ‘root’ as user and ‘example’ for a password if not changed

Please leave a comment or help to improve it here: https://github.com/assendk/MySQL57Docker-Compose-yml

Hits: 75

Share area

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up