Skip to content

Instantly share code, notes, and snippets.

@bradtraversy
Last active May 4, 2024 09:16
Show Gist options
  • Save bradtraversy/faa8de544c62eef3f31de406982f1d42 to your computer and use it in GitHub Desktop.
Save bradtraversy/faa8de544c62eef3f31de406982f1d42 to your computer and use it in GitHub Desktop.
Docker Compose FIle For Wordpress, MySQL & phpmyadmin

Wordpress & Docker

This file will setup Wordpress, MySQL & PHPMyAdmin with a single command. Add the code below to a file called "docker-compose.yaml" and run the command

$ docker-compose up -d

# To Tear Down
$ docker-compose down --volumes
version: '3'

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password 
    networks:
      - wpsite
  # Wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8000:80'
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:
@Prem1605
Copy link

Prem1605 commented Aug 25, 2021

Hi,
I did as advised and it is working fine in the local host. I tried deploying it to the Azure Web App but it shows the application error.
Am I missing something.??
Screenshot 2021-08-25 at 4 48 05 PM

@Prem1605
Copy link

After Troubleshooting. The web app is working.
The URL opens only PhpMyAdmin. How can I see Wordpress.??

@Prem1605
Copy link

Why is no volume line for the phpmyadmin.?

docker-compose down seems to destroy the DB and I get wordpress install next time I do docker-compose up -d
Any way to fix this?

Add a volume to db ;)

volumes:
    - db_data:/var/lib/mysql

or

volumes:
    - ./db-folder-data:/var/lib/mysql

Thanks @williamdes I already used that
volumes:

  • db_data:/var/lib/mysql
    but now it woks and does not seem to delete the db. Not sure what the problem was.
    Thanks anyway!

Why is no Volumes defined for phpmyadmin.??

@williamdes
Copy link

Why is no Volumes defined for phpmyadmin

phpMyAdmin does not need a volume, it's only a GUI

@Prem1605
Copy link

Why is no Volumes defined for phpmyadmin

phpMyAdmin does not need a volume, it's only a GUI

Thankyou.
After Deploying this yml file to Azure web app. I click on the URL and I am able to access only phpmyadmin. how to access wordpress.??

@mariosassine
Copy link

I keep getting an error after running the command '' docker-compose up -d ''

Error
'' Error response from daemon: can't access specified distro mount service: stat /run/guest-services/distro-services/debian.sock: no such file or directory "

@daironpf
Copy link

Hello, I just saw the video tutorial on youtube and everything went well for me.
Now I would like to connect my SQL Manager for MYSQL client to mysql that I have in docker, how could I do that?

@mdurchholz
Copy link

Are we certain that docker-compose down --volumes is the correct command to use in order to stop the container? After some tinkering, I have found that the "down" command will delete all of your volumes which leaves you with installing WP each time you run "docker-compose up -d".

So far, I have found a better solution of using docker-compose stop and docker-compose start after initially running docker-compose run -d command

@devmeireles
Copy link

my man! many thanks!!

@Nigrimmist
Copy link

Nigrimmist commented Apr 28, 2022

Still had a Database connection error. Working docker-compose for me :

version: '2'
services:
  wordpress:
    depends_on:
      - db
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306      
      WORDPRESS_DB_USER: admin
      WORDPRESS_DB_PASSWORD: admin
      WORDPRESS_DB_NAME: wordpress
    ports:
      - 8082:80
    networks:
      - myNetwork
  db:
    image: mysql
    restart: always
    volumes:
      - ./database:/var/lib/mysql    
    environment:
      MYSQL_ROOT_PASSWORD: admin
      MYSQL_DATABASE: wordpress
      MYSQL_USER: admin
      MYSQL_PASSWORD: admin
    networks:
      - myNetwork
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin
    restart: always
    ports:
      - 8083:80
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: admin
    networks:
      - myNetwork
networks:
  myNetwork:
volumes:
  database:

@williamdes
Copy link

Please use image: phpmyadmin instead of image: phpmyadmin/phpmyadmin

@Nigrimmist
Copy link

Yeap, updated 👍

@talhameer
Copy link

WORDPRESS_DB_NAME

Bundle of Thanks 👍

@soporteantumalal
Copy link

Alguien sabe si puedo modificar los puertos de BD por ejemplo se que ocupa 3306 y reemplazarlos por 1200 si se puede alguien me puede ayudar?

@bloggrammer
Copy link

- image: phpmyadmin/phpmyadmin
+ image: phpmyadmin

We have an official image, that will add some more security (official images scripts are audited before they go into the registry) ;)

The official image phpmyadmin is not working but phpmyadmin/phpmyadmin works fine. I am using mysql:debian and wordpress:latest images

@williamdes
Copy link

- image: phpmyadmin/phpmyadmin
+ image: phpmyadmin

We have an official image, that will add some more security (official images scripts are audited before they go into the registry) ;)

The official image phpmyadmin is not working but phpmyadmin/phpmyadmin works fine. I am using mysql:debian and wordpress:latest images

What do you mean by not working, it makes no sense they are the same sources 🤔?

@bloggrammer
Copy link

- image: phpmyadmin/phpmyadmin
+ image: phpmyadmin

We have an official image, that will add some more security (official images scripts are audited before they go into the registry) ;)

The official image phpmyadmin is not working but phpmyadmin/phpmyadmin works fine. I am using mysql:debian and wordpress:latest images

What do you mean by not working, it makes no sense they are the same sources 🤔?

By it's not working I mean the response body is empty when you try to access it on the web browser. Eg: localhost:8080 where 8080 is the binding port number. But phpmyadmin/phpmyadmin launch the login page for phpmyadmin

@williamdes
Copy link

- image: phpmyadmin/phpmyadmin
+ image: phpmyadmin

We have an official image, that will add some more security (official images scripts are audited before they go into the registry) ;)

The official image phpmyadmin is not working but phpmyadmin/phpmyadmin works fine. I am using mysql:debian and wordpress:latest images

What do you mean by not working, it makes no sense they are the same sources 🤔?

By it's not working I mean the response body is empty when you try to access it on the web browser. Eg: localhost:8080 where 8080 is the binding port number. But phpmyadmin/phpmyadmin launch the login page for phpmyadmin

That's weird, can you send the docker compose block?
Try to docker pull phpmyadmin and re start it

@osintkol
Copy link

Thank you so much for sharing. This has helped.

@f2ka07
Copy link

f2ka07 commented Apr 16, 2023

I have even gone ahead and used IP addresses in docker-compose for my containers. Great Video Dockerize WordPress & MYSQL: Use Docker Compose to create a container with static/fixed IP for external network between containers.

@btarg
Copy link

btarg commented May 1, 2023

This doesn't work when using it on an Oracle Cloud Instance under Ubuntu 22.04. I have changed the image to use the official phpmyadmin instead of phpmyadmin/phpmyadmin but still no luck. I also can't setup a reverse proxy with nginx to point to it either like I have done successfully with my other docker services like psitransfer. What should I do?

@williamdes
Copy link

This doesn't work when using it on an Oracle Cloud Instance under Ubuntu 22.04. I have changed the image to use the official phpmyadmin instead of phpmyadmin/phpmyadmin but still no luck. I also can't setup a reverse proxy with nginx to point to it either like I have done successfully with my other docker services like psitransfer. What should I do?

This gist is not a support forum, but please send your docker compose file and associated config files

@sasathegoth
Copy link

I have a problem with the themes in WP. There is always the error, that my theme is broken. Is this a problem from WP or from the docker-compose file?

@bloggrammer
Copy link

bloggrammer commented May 3, 2023

I have a problem with the themes in WP. There is always the error, that my theme is broken. Is this a problem from WP or from the docker-compose file?

It's from WP. Are you trying to migrate from an existing WP site?

@opsquid
Copy link

opsquid commented May 16, 2023

Thank you. All working fine for me. Just had to restart the container to make it work.

@dinki
Copy link

dinki commented Oct 31, 2023

Thanks for providing this. Works great for my use. Only one question: where can I find php.ini? I need to increase the max file size upload to add a manual addon and some images are too large for the default value.

@SimoneZacchetti
Copy link

I'm trying to run it on a M1 Pro and I'm having this error when doing docker-compose up -d :
no matching manifest for linux/arm64/v8 in the manifest list entries

@williamdes
Copy link

@lvnh2003
Copy link

Hello ereryone, after I use this code, I am able to access only phpmyadmin. how to access wordpress. Help me please
image

@niklasdahlheimer
Copy link

Maybe this helps anyone out there..

In my case the network driver was missing. So connections to the DB could not be established. Adding driver: bridge fixed it for me

networks:
  wpsite:
   driver: bridge

Maybe that happend because I added a second proxy network to connect WP and phpMyAdmin to my ReverseProxy...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment