Preface
Goal: Setting-up docker-compose to run phpmyadmin.
We need to see how we can use docker in real life with docker-compose
to setup a phpmyadmin site in localhost.
Summary
As a summary, the command we need to use is as simple as these below:
❯ docker compose pull
[+] Running 2/2
⠿ phpmyadmin Pulled 2.9s
⠿ db Pulled 2.9s
❯ docker compose up -d
[+] Running 2/2
⠿ Container db Started 0.4s
⠿ Container pma Started 0.8s
❯ docker ps -a --format 'table {{.Names}}\t{{.Status}}'
NAMES STATUS
pma Up 8 seconds
db Up 8 seconds
❯ docker compose stop
[+] Running 2/2
⠿ Container pma Stopped 1.2s
⠿ Container db Stopped 1.4s
❯ docker ps -a --format 'table {{.Names}}\t{{.Status}}'
NAMES STATUS
pma Exited (0) 4 seconds ago
db Exited (0) 2 seconds ago
❯ docker compose rm -f
Going to remove pma, db
[+] Running 2/0
⠿ Container db Removed 0.0s
⠿ Container pma Removed 0.0s
❯ docker ps -a --format 'table {{.Names}}\t{{.Status}}'
NAMES STATUS
❯ docker compose down
[+] Running 1/1
⠿ Network dockerngadimin_default Removed 0.1s
❯ docker-compose build --pull
The output while the docker running is as below:
Installation
We need to install one more package.
❯ sudo pacman -S docker-compose
resolving dependencies...
looking for conflicting packages...
Packages (1) docker-compose-2.16.0-1
Total Installed Size: 49.87 MiB
:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring
(1/1) checking package integrity
(1/1) loading package files
(1/1) checking for file conflicts
(1/1) checking available disk space
:: Processing package changes...
(1/1) installing docker-compose
Configuration
For this example, I copy-paste the configuration from site below:
Consider make a new directory for our new project. PHPMyAdmin in Docker.
❯ mkdir dockerngadimin
❯ cd dockerngadimin
and make new file named docker-compose.yml
.
The YAML configuration would be as below:
version: '3'
services:
db:
image: mysql:5.7
container_name: db
environment:
MYSQL_ROOT_PASSWORD: blewah
MYSQL_DATABASE: app_db
MYSQL_USER: db_user
MYSQL_PASSWORD: db_user_pass
ports:
- "6033:3306"
volumes:
- dbdata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: pma
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
volumes:
dbdata:
In that directory you can start with, pulling the docker image into your linux system.
❯ docker-compose pull
[+] Running 31/2
⠿ db Pulled 39.1s
⠿ phpmyadmin Pulled 27.9s
The first pull will download the docker image. This might take a few seconds long.
❯ sudo pacman -S docker-compose resolving dependencies… looking for conflicting packages…
Packages (1) docker-compose-2.16.0-1
Total Installed Size: 49.87 MiB
:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring
(1/1) checking package integrity
(1/1) loading package files
(1/1) checking for file conflicts
(1/1) checking available disk space
:: Processing package changes…
(1/1) installing docker-compose
Case: PHPMyAdmin
Consider have case, such as having phpmyadmin installed as docker. This way, we do not pollute the main system. We can break down the step one by one.
Pull
We can start by pulling the docker.
❯ docker compose pull
[+] Running 2/2
⠿ phpmyadmin Pulled 3.0s
⠿ db Pulled 3.0s
Up as Daemon
Then running as service
❯ docker compose up -d
[+] Running 2/2
⠿ Container db Started 0.4s
⠿ Container pma Started 0.8s
Preview in Browser
Now we can open the PHPMyAdmin in any browser.
❯ docker compose stop
[+] Running 2/2
⠿ Container pma Stopped 1.2s
⠿ Container db Stopped 1.4s
Stop
You don’t need to stop the process. But if you wish, you can just stop the daemon, for local directory.
❯ docker compose rm -f
Going to remove pma, db
[+] Running 2/0
⠿ Container db Removed 0.0s
⠿ Container pma Removed 0.0s
After stopping, the docker process would show nothing.
❯ docker ps -a --format 'table {{.Names}}\t{{.Status}}'
NAMES STATUS
Down
I’m not sure about this.
❯ docker compose down
[+] Running 1/1
⠿ Network dockerngadimin_default Removed 0.1s
I just like to issue some command.
What is Next 🤔?
You might be interested in see what happened to the docker image.
Consider continue reading [ Docker - Image ].
Thank you for reading.