opened image

    In this article, we will look at how to install phpMyAdmin in a Docker container, as well as review the syntax of the docker-compose file and perform the installation.

    First, let's install Docker. 

    Update the 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 | sudo apt-key add -
    add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"


    Now update the packages with the new repository:





    apt update


    Now let's install Docker itself.





    apt-get install docker-ce docker-ce-cli


    Check the Docker version:





    docker --version


    Check the status:





    systemctl status docker


    If it didn't start, then start it:





    systemctl start docker


    And add it to autostart.





    systemctl enable docker





    Install Docker-Compose




    curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

    Set execution permissions. 




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


    Check how Docker-Compose was installed:





    docker-compose --version


    Create a *.yaml file for Docker-Compose.

    To keep track of where and what we have installed in the future, 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. 

    Use the repository to create the docker-compose.yaml file from the link

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





    vim docker-compose.yaml


    And add the following code to it:





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



    phpmyadmin: the name of your container;
    image: phpmyadmin: the 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 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)

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





    docker-compose up -d 


    Wait for the images to download and deploy.






    docker-compose ps







    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 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.