Blog

How to Build and run phpMyAdmin in a Docker container?

Docker / PHPMyAdmin

How to Build and run phpMyAdmin in a Docker container?

phpMyAdmin is a web-based tool for managing MySQL databases, and Docker allows you to easily containerize and run applications.To build and run phpMyAdmin in a Docker container, you’ll need to follow a series of steps.

Install Docker:
If you don’t have Docker on your system you need to install. You can download it from the official Docker website (https://www.docker.com/get-started).

Install Docker Compose:
Docker Compose is a tool for describing and running multi-container Docker applications. It is helpful for setting up more complex environments. You can install it from here: https://docs.docker.com/compose/install/.

Create a Project Directory:
Create a directory for your project and navigate to it in your terminal.

Create a docker-compose.yml File:
Inside the project directory, create a docker-compose.yml file. This file will describe your Docker services and their configurations.

Describe Services in docker-compose.yml:
Add the following content to your docker-compose.yml file:

version: '3.1'
services:
  phpmyadmin:
    container_name: PHPMyAdmin
    image: phpmyadmin
    restart: always
    ports:
      - 8081:80
    environment:
      - PMA_ARBITRARY=5
      - PMA_HOST=<DB_HOSTNAME>

Note: <DB_HOSTNAME> just add your hostname

Run the Docker Compose Command:
In your terminal, navigate to your project directory and run the following command to start the containers:

docker-compose up -d

The -d flag runs the containers in the background.

Access phpMyAdmin:
Open a web browser and go to http://localhost:8080. You should see the phpMyAdmin login page. Use your MySQL credentials to log in.

Stopping and Cleaning Up:
To stop and remove the containers, use the following command:

docker-compose down

The above Docker Compose setup will create a phpMyAdmin container and connect it to your MySQL server. The phpMyAdmin interface will be accessible at http://localhost:8080.

Spread the love

Leave your thought here

Your email address will not be published. Required fields are marked *