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:
@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