Docker Community Forums

Share and learn in the Docker community.

Docker-compose.yml with MariaDB, Wordpress, Adminer + persistent

Hi,

I looked for many tutorials but can’t find one with MariaDB + Wordpress + Adminer.
Here’s my docker-compose.yml :

version: '3.3'
services:
db:
 image: mysql:5.7
 volumes:
   - db_data:/var/lib/mysql
 restart: always
 environment:
   MYSQL_ROOT_PASSWORD: somewordpress
   MYSQL_DATABASE: wordpress
   MYSQL_USER: wordpress
   MYSQL_PASSWORD: wordpress

wordpress:
 depends_on:
   - db
 image: wordpress:latest
 ports:
   - "8000:80"
 restart: always
 environment:
   WORDPRESS_DB_HOST: db:3306
   WORDPRESS_DB_USER: wordpress
   WORDPRESS_DB_PASSWORD: wordpress
   WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}

May someone direct me to an easy tutorial or send me a docker-compose.yml with the services : MariaDB, Wordpress, Adminer and a persistent volume to store changes ?
This is just to make some trials an do a demo with Wordpress.

Thanks

Michael

You mean like this? (I’m new, so still learning)

version: '3'

services:

  # Database

  db:

    container_name: database

    image: mariadb

    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:

    container_name: phpmyadmin

    depends_on:

      - db

    image: phpmyadmin

    restart: always

    ports:

      - '8080:80'

    environment:

      PMA_HOST: db

      MYSQL_ROOT_PASSWORD: password 

    networks:

      - wpsite

  # Wordpress

  wordpress:

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

Actualy it would help a lot if you guys would paste the content of the compose.yml as preformated text </>.

update: which was corrected for doogonston’s post while I posted my comment.

1 Like

I was trying :slight_smile: Second post here hahaha, so had to find out :blush:

Welcome to the forum then! :slight_smile:

1 Like

Thanks doogoston. Was more looking to use Adminer instead of phpmyadmin.

Preformated too meyay.

Sorry I’m truly a newbie : why the networks : - wpsite ?

It does work but I can only stop the services with ctrl+c can’t do a docker-compose down

it is a named custom network. Docker compose by default creates a “default” network otherwise. It allows to declare multiple networks, and specifiy which service should be part of which network(s).

Would you mind sharing how you start your compose deployment?

I added the compe.yml snippet from adminers dockerhub page to your example (and re-ordered it a little):

version: "2.4"

services:
  db:
    image: mysql:5.7
    restart: always
    networks:
      - wpsite
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db_data:/var/lib/mysql

  adminer:
    image: adminer:latest
    restart: always
    depends_on:
      - db
    networks:
      - wpsite
    ports:
      - 8080:8080

  wordpress:
    image: wordpress:latest
    restart: always
    depends_on:
      - db
    networks:
      - wpsite
    ports:
      - 8000:80
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html

networks:  
  wpsite: {}

volumes:
  db_data: {}
  wp_data: {}

Stick with latest v2.x compose version if you only use docker-compose. You loose some configuration items if you use v3.x, which is intended for swarm stack deployments.

Thanks meyay for your help, explanations and version tip.

I’m starting the services with:

docker-compose up

Using the .yml you sent I get the following error:

db_1 | stack_bottom = 0 thread_stack 0x40000
db_1 | mysqld(my_print_stacktrace+0x2c)[0x5594b65cbe7c]
db_1 | mysqld(handle_fatal_signal+0x501)[0x5594b5ee2f01]
db_1 | /lib/x86_64-linux-gnu/libpthread.so.0(+0x12730)[0x7fe760d65730]
db_1 | mysqld(_Z11ut_crc32_swPKhm+0x647)[0x5594b68e7aa7]
db_1 | mysqld(_Z22page_zip_calc_checksumPKvm24srv_checksum_algorithm_tb+0x77)[0x5594b68004d7]
db_1 | mysqld(_Z24page_zip_verify_checksumPKvm+0xa8)[0x5594b68005f8]
db_1 | mysqld(_Z21buf_page_is_corruptedbPKhRK11page_size_tb+0x35a)[0x5594b69280ea]
db_1 | mysqld(_ZN8Datafile19validate_first_pageEPmb+0x431)[0x5594b69af6d1]
db_1 | mysqld(_ZN13SysTablespace24read_lsn_and_check_flagsEPm+0x78)[0x5594b69b5ea8]
db_1 | mysqld(ZN13SysTablespace14open_or_createEbbPmS0+0x372)[0x5594b69b7a62]
db_1 | mysqld(_Z34innobase_start_or_create_for_mysqlv+0x2630)[0x5594b689fa40]
db_1 | mysqld(+0xf88640)[0x5594b6771640]
db_1 | mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x55)[0x5594b5f34025]
db_1 | mysqld(+0xbe0906)[0x5594b63c9906]
db_1 | mysqld(_Z40plugin_register_builtin_and_init_core_sePiPPc+0x1dc)[0x5594b63cb7dc]
db_1 | mysqld(+0x6f2e8e)[0x5594b5edbe8e]
db_1 | mysqld(_Z11mysqld_mainiPPc+0x758)[0x5594b5edd338]
db_1 | /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb)[0x7fe76082d09b]
db_1 | mysqld(_start+0x2a)[0x5594b5ed3c3a]
db_1 | The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
db_1 | information that should help you find out what is causing the crash.
sgs_db_1 exited with code 2

You might want to cleanup the volume, as it may contain inconsistant files from your old attempts:

1… docker volume ls, find the {project name}_db_data volume
2. docker volume rm {project name}_db_data
3. docker-compose up -d

By default the project name for the docker-compose stack is the folder name where the docker-compose.yml is in.

I just tested it on Ubuntu 18.04/Docker 20.04: works like a charm.

update: I remembered there is an easier approach to delete the volumes: docker-compose down --volumes

Works great !

docker-compose down --volumes

The above command definetely fixed it.
Thanks again for your help !

This post was flagged by the community and is temporarily hidden.