Learn the simplest way to start your MySQL database with Docker with only two commands.
Docker is an open-source project that automates the deployment of applications inside software containers. These containers will be used to isolate our MySQL server and phpMyAdmin client.
- Install Docker - On Windows or Mac, go to: https://docs.docker.com/engine/installation/
- On Linux, just run on terminal:
curl -sSL https://get.docker.com/ | sh
2. Create MySQL container
The following command will create a MySQL container. Below I’ll explain the params. Just change as you wish and adapt to your use.
2.1. On Linux
Create a directory for database data and create the container.
# Create dir for database data mkdir -p /opt/mysql # Create MySQL container docker run –-name mysql -v /opt/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=pass_here -p 3306:3306 -d mysql
2.2. On Windows
For Windows, I recommend you to create all containers without set volumes and set volume after, on Kitematic.
Run on Docker Terminal / Powershell:
# Create MySQL container docker run –-name mysql -e MYSQL_ROOT_PASSWORD=pass_here -p 3306:3306 -d mysql
Now create volume from Kitematic as the image below:
3. Create phpMyAdmin container
The following command will create a phpMyAdmin container. You will need to link to MySQL container, so the phpMyAdmin can connect and access databases.
Works on Linux and Windows:
docker run –-name phpmyadmin \ # Container name -–link mysql:db \ # Link to MySQL container -p 8080:80 \ # Port -d phpmyadmin/phpmyadmin # Run as daemon
4. Access the database
Go to the browser and access the phpMyAdmin. The default user is “root” and password will the password set on MySQL container creation.
If you have any questions, just leave the comments below. I’ll try to help you as best I can. ^^