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 a Docker network
The phpMyAdmin most communicate each other so is necessary create a Docker network and add both into it.
# Create the network called "asgard" docker network create asgard
3. Create the MySQL container
The following command will create a MySQL container. Below I'll show you the params. Change as you wish and adapt to your use.
# Create dir for database data mkdir -p /opt/mysql # Create MySQL container docker run -d \ --name asgard-mysql \ --network asgard \ -e MYSQL_ROOT_PASSWORD="OuPfme45oAM6m6S8lqy4PQfxlYFlCnmPzyaloZ5Zw=" \ -v /opt/mysql:/var/lib/mysql \ -p 3306:3306 \ mysql:8.0.12
4. Create the 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.
# Create phpMyAdmin container # # PMA_HOST is the IP or domain of the MySQL server, # so we can use the MySQL container name as the domain # cause the Docker network create the route as a DNS server. docker run -d \ --name asgard-phpmyadmin \ --network asgard \ -e PMA_HOST=asgard-mysql \ -p 8080:80 \ phpmyadmin/phpmyadmin:edge
5. 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. ^^