Zomro » FAQ » How to install phpMyAdmin in Docker
flag We stand with Ukraine. To make an impact, please consider donating. More details.
In this article, we will look at how to install phpMyAdmin in a Docker container, we will also look at the syntax of the docker-compose file and install it in the same way.

First, let's install Docker.
Update OS packages.

apt update

Install the necessary packages and add a new repository:

apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Now let's update the packages with the new repository:

apt update

Now let's install Docker itself.

apt-get install docker-ce docker-ce-cli containerd.io

Checking Docker version:

docker --version


Let's check the status:

systemctl status docker


If it does not start, then run:

systemctl start docker

And add to autorun.

systemctl enable docker


Install Docker Compose

curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin /docker-compose

Set permissions to launch.

chmod +x /usr/local/bin/docker-compose

Check how Docker-Compose was installed:

docker-compose --version



Let's create a *.yaml file for Docker-Compose.

To navigate in the future where and what we have installed, let's create a separate folder for this project in the /home directory and go to it.

mkdir /home/phpmyadmin && cd /home/phpmyadmin

You can also use a different directory to host this and other projects.

Let's use the repository to create the docker-compose.yaml file at https://hub.docker.com/_/phpmyadmin

Create a docker-compose.yaml or docker-compose.yml file,

vim docker-compose.yaml
And add the following code to it:

version: '3.1'
services: phpmyadmin: image: phpmyadmin restart: always ports: - 8090:80 environment:
      - PMA_ARBITRARY=1


Where:

phpmyadmin: name of your container;
image: phpmyadmin: image from which phpmyadmin will be deployed
8090:80 - port 8090 which we will use to connect to phpmyadmin
restart:always - indicates that the container will be restarted when the server crashes or restarts
PMA_ARBITRARY=1 - indicates that it is possible to connect to an arbitrary database server (How to bind a phpmyadmin panel to a specific server can be found in this article)

Run our script (for this you need to be in the directory where our file was created. In this case, it is /home/phpmyadmin):

docker-compose up -d
We are waiting for the download of images, and deployment.

We check:

docker-compose ps
or

docker ps


To view the logs, use the command
docker logs -f phpmyadmin

You can also install only in docker:

docker run -d --restart always --name phpmyadmin -e PMA_ARBITRARY=1 -p 8090:80 phpmyadmin

To connect to PhpMyAdmin - open a browser and go to - http://YOUR_IP_SERVER:8090/

Now we can connect the database server.
In the Server field, enter the IP of the database server, in the Username field - the user (in this case, it is root), in the Password field - the password of the database server root user.

If you have not yet installed a database server in Docker, then in the article How to install MariaDB in Docker we will look at how to do this, and we will see how to deploy this server, databases with phpMyAdmin.