WordPress and docker – Using phpmyadmin with docker and wordpress and mysql

This is a bonus post. I got curious about running a phpmyadmin instance and realised it was easy to get running.

If you’ve gone through my previous posts:

Or perhaps you already have an instance of wordpress running and a database that has persistence set up. Now you want to add a mysql administration tool into the mix.

For this I did not go out of my way to write a full docker-compose.yml file. I only wanted a phpmyadmin instance running locally for testing any wordpress development.

To do this I ran:

1
2
3
4
$ docker run
    --name myadmin
    --network dockerwordpress_default -d
    --link dockerwordpress_db_1:db -p 8080:80 phpmyadmin/phpmyadmin

The steps involved

The important part is making sure you link to your db and that you run the phpmyadmin container on the same network as the db.

First see what the name of your db container is:

1
$ docker ps

You should something like this:

1
2
3
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81ba5a434e49 wordpress:latest "docker-entrypoint..." 23 hours ago Up 23 hours 0.0.0.0:8000->80/tcp dockerwordpress_wordpress_1
549f46a13b6b mysql:5.7 "docker-entrypoint..." 23 hours ago Up 23 hours 3306/tcp dockerwordpress_db_1

Your mysql container is the important one for this post. Copy the name, in my case it is “dockerwordpress_db_1”.

Check your networks:

1
$ docker network ls

You should see something like this:

1
2
3
4
5
NETWORK ID NAME DRIVER SCOPE
1db6773f4c13 bridge bridge local
938a9daa793d dockerwordpress_default bridge local
d8e0c5970cdb host host local
40e39b778c65 none null local

In my case I would use “dockerwordpress_default” as the network for my phpmyadmin container.

Using docker run

Now you know enough to run the command that I showed at the start of the post:

1
2
3
4
$ docker run
    --name myadmin
    --network dockerwordpress_default -d
    --link dockerwordpress_db_1:db -p 8080:80 phpmyadmin/phpmyadmin

Explanations of the important parts:

–link dockerwordpress_db_1:db

dockerwordpress_db_1:db this is pointing to the network “dockerwordpress_db_1” and then linking to the mysql database service which you would have started in this post: Running wordpress and mysql using docker compose

–network dockerwordpress_default

dockerwordpress_default You got this when you ran docker network ls above.

Viewing phpmyadmin

If your phpmyadmin container started up successfully you should now be able to connect to it on port 8080.

If your docker is linked to your localhost:

http://localhost:8080

Alternativelyl find your ip by running:

1
$ docker-machine ip

Then

http://yourdckerip:8080

Login to phpmyadmin using the details you used in the docker configurations:

Eg

1
2
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress