Run MySQL Server on Top of Docker
Docker is a OS based virtualized environment, its lightweight and easily to deploy in multiple kind of environment (.e.g. mac, windows, linux). Unlike virtual machine, docker is not require the entire of operating system nor kernel to live.
MySQL is widely use relational database that backed by Oracle, its open source and freely to use.
—
Some of software engineer nowadays might develop multiple application on his local environment, and each application might have one database, also somehow the application is dependent with spesific version of database. Without run any virtualized environment, the environment can only run one database server and version.
In term of flexibility and simplicity, run MySQL server in Docker is one of the cleanest approach for developing application while in development stage, cause it can run, stop or migrate the server seamlessly.
Here to start
1. Install Docker
Docker is an open source that provide Docker Community Edition so its freely to use.
to install, you can download it through this link.
after the installation succeed, verify it with docker version.
2. Pull MySQL Image
MySQL Image is available in Docker Hub. We can pull any version we want just passing one of these tag:
docker pull mysql:latest
docker pull mysql:8.0.2
docker pull mysql:5
The output result shown below:
Then verify the images with, docker images
3. Run MySQL image
Start the MySQL Server with non empty root password.
docker run --name mysql-name --restart unless-stopped -e MYSQL_ROOT_PASSWORD=password -p 3310:3306 -d mysql:5
after executed, see the current status of MySQL Server with docker ps -a.
4. Log In to MySQL Server
docker exec -it mysql-name mysql -u root -p
Log in to MySQL server using root password that previously defined.
6. Stop/Start MySQL Server
These are basic docker operation to stop and start the server.
docker stop mysql-namedocker start mysql-name
5. Connect using MySQL Client (Optional)
MySQL Client is a GUI interface to manage MySQL Server operations (e.g. create table, select table, and etc). There are several MySQL client software that widely use; MySQL Workbench, Sequel Pro, DBeaver, and etc.
Setup the connection toward MySQL Server (MySQL Client Workbench)
It’s all wrap up! MySQL Server is ready to serve.
Hope it will help, happy trying!
refferences:
https://severalnines.com/database-blog/mysql-docker-containers-understanding-basics
https://nextbreakpoint.com/posts/article-run-mysql-in-docker-container.html