Quick way to deploy MySQL and phpMyAdmin with Docker
2 min read
In this article, we'll look at how to quickly start the MySQL database management system with phpMyAdmin. For speed of launch and better control, we will use Docker
Often for local development we need a database, so this article will help us in this matter to start MySQL
MySQL
First, select the required MySQL version from the https://hub.docker.com/_/mysql repository. In this case, it’s 5.7.42
Next, we will come up with a name for the container, open port 3306, specify the volume for data storage and set the password for the root user in the MYSQL_ROOT_PASSWORD variable
We will have the following configuration:
mdb:
image: mysql:5.7.42
container_name: mdb
restart: always
environment:
- MYSQL_ROOT_PASSWORD=1234
ports:
- "3306:3306"
volumes:
- mdata:/var/lib/mysql
networks:
- mnetwork
The network is additionally indicated here for further connection with the phpMyAdmin container
phpMyAdmin
Now let’s configure the phpMyAdmin container and link it to our container for MySQL
Specify that phpMyAdmin be available on port 8081 (http://localhost:8081)
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
ports:
- "8081:80"
links:
- "mdb:db"
depends_on:
- mdb
networks:
- mnetwork
Final docker-compose.yml file
Now it remains for us to create a volume for storing database data and set up a network so that containers work within the same network
volumes:
mdata:
networks:
mnetwork:
driver: bridge
As a result, we got the following docker-compose.yml file, and we can run docker-compose up
version: '3.9'
services:
mdb:
image: mysql:5.7.42
container_name: mdb
restart: always
environment:
- MYSQL_ROOT_PASSWORD=1234
ports:
- "3306:3306"
volumes:
- mdata:/var/lib/mysql
networks:
- mnetwork
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
ports:
- "8081:80"
links:
- "mdb:db"
depends_on:
- mdb
networks:
- mnetwork
volumes:
mdata:
networks:
mnetwork:
driver: bridge
You’re all set, thanks for reading!