Introduce
- MySQL: MySQL is an open-source relational database management system (RDBMS). Many web applications widely use it, and it forms a central component of the LAMP (Linux, Apache, MySQL, PHP/Python/Perl) and MERN (MongoDB, Express.js, React, Node.js) stacks
- Adminer: Adminer is a lightweight and user-friendly database management tool written in PHP. It allows you to manage MySQL, PostgreSQL, SQLite, MS SQL, and Oracle databases through a web-based interface.
- Docker: Docker is a platform for developing, shipping, and running applications in containers. Containers are lightweight, portable, and self-sufficient, encapsulating everything needed to run an application, including the code, runtime, libraries, and dependencies.
- Docker Compose: Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define a multi-container environment in a single file, making it easier to manage and deploy complex applications.
- In this blog, we will discuss how to deploy MySQL and Adminer with Docker Compose
Preparation
To get started, the initial step is to install Docker and Docker Compose. Detailed instructions can be found in this link. Once this installation is complete, you’re ready to dive into the powerful features that Docker brings to the table. Get ready to explore a world of seamless containerization and efficient deployment!
Create a Docker Compose YAML file
Now, prepare yourself and start the process by creating a new folder and navigating to it:
mkdir mysql-compose
cd mysql-compose
Create a new file named docker-compose.yaml
and use the following code
version: "3.5"
services:
mysql:
image: mysql:8.2.0
container_name: "mysql"
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: "mysql_password"
volumes:
- [path-to-store-mysql-data]:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Adjust certain points to suit your specific situation:
MYSQL_ROOT_PASSWORD
[path-to-store-mysql-data]
Save the file once you make the adjustments.
Start docker compose
Now, you simply need to run a single-line command to start both MySQL and Adminer:
docker compose up
or
docker compose up -d
to start it as a daemon.
Check the results
Awesome! You can access Adminer using the link http://your-ip-server:8080 to get started.
Let’s attempt to connect to MySQL on port 3306 with user root
Clean up after running Docker Compose
After usage, you can tidy up by running the command
docker compose down
Summary
That is an easy and quick way to deploy MySQL and Adminer with Docker Compose, even if you are a beginner. I hope you will succeed in deploying it. Check out other useful tips on the Toan Thien blog.
What is your favorite database? Is MySQL a good choice? Let me know your opinion. Thank you for your interest!