Introduction
phpMyAdmin is a free and open source administration tool for MySQL and MariaDB. As a portable web application written primarily in PHP, it has become one of the most popular MySQL administration tools, especially for web hosting services.
The Docker Compose File
---
version: "3.8"
services:
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin
hostname: phpmyadmin
restart: unless-stopped
security_opt:
- no-new-privileges:true
env_file:
- .env
environment:
- TZ=${TZ}
# - PMA_ABSOLUTE_URI=${PMA_ABSOLUTE_URI}
# - PMA_ARBITRARY=${PMA_ARBITRARY}
- PMA_HOST=${PMA_HOST}
# - PMA_HOSTS=${PMA_HOSTS}
- PMA_PORT=${PMA_PORT}
ports:
- 80:80
volumes:
- /opt/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
- /opt/phpmyadmin/sessions:/sessions
- /opt/phpmyadmin/themes/theme:/var/www/html/themes/theme/
- /etc/localtime:/etc/localtime:ro
labels:
- com.centurylinklabs.watchtower.enable=true
docker-compose.yml
The Docker Environment Variables File
TZ=Europe/Stockholm
# PMA_ARBITRARY=1
# PMA_ABSOLUTE_URI=https://mywebsite.com
PMA_HOST=database_1
# PMA_HOSTS=database_1,database_2,database_3
PMA_PORT=3306
.env
This Docker Compose file defines a single service named “phpmyadmin”. The service is built from the “phpmyadmin:latest” Docker image, which is the latest version available. The container name is set to “phpmyadmin” as well.
The “restart” section ensures that the container will always be restarted if it exits (unless manually stopped). This is useful for ensuring that the service is always available, especially if it crashes or is shut down unexpectedly.
The “security_opt” section prevents your container processes from gaining additional privileges. This is an important security consideration.
The “ports” section maps port 80 on the host machine to port 80 in the container. This allows us to access the phpMyAdmin web interface from our local machine. By default, phpMyAdmin runs on port 80, but you can change it if necessary.
The “volumes” section maps the "config.user.inc.php" file, this is where you can store extra configuration settings if you need to. The "sessions" directory is also needed to store information regarding each active session in the software. The "themes" directory is also mapped to allow for custom themes (Personally, I really like "boodark-teal", which is a dark/green theme).
The "labels" section allows the Watchtower service to keep this container update automatically.
Running phpMyAdmin with Docker Compose
To run phpMyAdmin with Docker Compose, first, make sure you have Docker and Docker Compose installed on your machine. Then, create a new directory for your Nextcloud project and save the above Docker Compose file as “docker-compose.yml” in that directory along with the environment variables as “.env”.
Next, run the following command from the same directory:
docker compose up -d
This command will start the phpmyadmin container in the background and detach from it. You can then access the phpMyAdmin web interface by going to http://localhost in your web browser.
Conclusion
In this article, we explored how to set up and run the phpMyAdmin software using Docker Compose. We looked at the different sections of the Docker Compose file and explained how they work together to create a functional phpMyAdmin service. By running phpMyAdmin with Docker Compose, you can easily deploy and manage the tool on your own server, without having to worry about dependencies or configuration.
