How to install MySQL and phpMyAdmin with Docker

docker Jan 27, 2017

Learn the simplest way to start your MySQL database with Docker with only two commands.

Docker is a project that automates the deployment of applications inside software containers. These containers will be used to isolate our MySQL server and phpMyAdmin client.

1. Requirements

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.

To get access to phpMyAdmin, go to: http://localhost:8080/
In my case, I was running on a Virtual Machine and I was accessing it from a different IP address.

phpmyadmin_docker

Questions?

If you have any questions, just leave the comments below. I'll try to help you as best I can. ^^

References

Tags

Luiz Costa

I am a senior software engineer at Red Hat / Ansible. I love automation tools, games, and coffee. I am also an active contributor to open-source projects on GitHub.