In this article, we will look at how to install phpMyAdmin in a Docker container, as well as the syntax of the docker-compose file and also perform the installation.
Installing Docker
We update the OS packages.
apt update
We will 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 we will update the packages with the new repository:
apt update
Now we will install Docker itself.
apt-get install docker-ce docker-ce-cli containerd.io
We check the Docker version:
docker --version
Let's check the status:
systemctl status docker
If it did not start, we start it:
systemctl start docker
And add it to autostart.
systemctl enable docker
Let's 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
We set the execution permissions.
chmod +x /usr/local/bin/docker-compose
We check how Docker-Compose was installed:
docker-compose --version
Let's create a *.yaml file for Docker-Compose.
To orient ourselves in the future about where and what we have installed, we will create a separate folder for this project in the /home directory and navigate to it.
mkdir /home/phpmyadmin && cd /home/phpmyadmin
You can also use another directory to place this and other projects.
We will use the repository to create the docker-compose.yaml file at the link https://hub.docker.com/_/phpmyadmin
We create the file docker-compose.yaml or docker-compose.yml,
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: the name of your container;
image: phpmyadmin: the image from which phpmyadmin will be deployed
8090:80 - port 8090 that we will use to connect to phpmyadmin
restart:always - indicates that the container will be restarted in case of failure or server reboot
PMA_ARBITRARY=1 - indicates that it is possible to connect to an arbitrary database server (How to bind the phpmyadmin panel to a specific server can be found in this article)
We 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 wait for the images to download and deploy.
We check:
docker-compose ps
or
docker ps
To view the logs, use the command
docker logs -f phpmyadmin
You can also perform the installation only in docker:
docker run -d --restart always --name phpmyadmin -e PMA_ARBITRARY=1 -p 8090:80 phpmyadmin
To connect to phpmyadmin — open your browser and go to the address — http://YOUR_IP_SERVER:8090/
Now we can connect to 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 root user of the database server.
If you have not yet installed the database server in Docker, then in the article How to install MariaDB in Docker we will look at how to do this, and see how to deploy this database server along with phpMyAdmin.
We also suggest looking at other useful articles: