Skip to content

Instantly share code, notes, and snippets.

@bradtraversy
Last active July 21, 2024 05:00
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:
@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...

@devSahinur
Copy link

updated docker_wordpress.md


version: '3.9'

services:
  # Database
  db:
    image: mysql:8.0
    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:latest
    restart: always
    ports:
      - '8081: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:
      - ./wordpress:/var/www/html
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite

networks:
  wpsite:


volumes:
  db_data:


@williamdes
Copy link

This is wrong, the phpmyadmin container does not have a MYSQL_ROOT_PASSWORD variable.
It should be PMA_PASSWORD used with a PMA_USER. See phpmyadmin

@loeweh
Copy link

loeweh commented Jun 18, 2024

Hi, getting the notification that Mailpoet needs the mysql_pdo extension. does anyone know if there is a wordpress container that has the extension installed? Thanks

@mrfzd
Copy link

mrfzd commented Jul 11, 2024

updated docker_wordpress.md


version: '3.9'

services:
  # Database
  db:
    image: mysql:8.0
    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:latest
    restart: always
    ports:
      - '8081: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:
      - ./wordpress:/var/www/html
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite

networks:
  wpsite:


volumes:
  db_data:

Many thanks, however, we are having issues where when we are making changes to our WordPress theme locally we don't see them reflected despite the volumes!
Not entirely sure if anybody tested theme or plugin development locally that would be reflected seamlessly!

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