1

I am trying to setup wordpress with docker. I have included my yaml file below. Here I have set my mariadb_database to db_tyre.

When I hit docker-compose up -d, it is creating all the required files of wordpress. This is also creating db_tyre database but when I try localhost:8000, it gives me Error establishing a database connection.

I have checked the wp-config.php file, it has following lines.

define( 'DB_NAME', 'wordpress');

/** MySQL database username */
define( 'DB_USER', 'wordpress');

/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress');

/** MySQL hostname */
define( 'DB_HOST', 'mariadb:3306');

yml file

version: '3'

services:
  # Database
  db:
    image: bitnami/mariadb:latest
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: password
      MARIADB_DATABASE: db_tyre
      MARIADB_USER: wordpress
      MARIADB_PASSWORD: wordpress
    networks:
      - wpsite
  # Wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8000:80'
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: mariadb:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_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
networks:
  wpsite:
volumes:
  db_data:
3
  • 1
    you should change the db-host to define( 'DB_HOST', 'db:3306') as the service-name you use in docker-compose Commented Feb 13, 2020 at 10:33
  • @invad0r how about DB_NAME and DB_USER.? Commented Feb 13, 2020 at 10:47
  • they should be fine as they are Commented Feb 13, 2020 at 11:19

1 Answer 1

2

As mentioned in the comment, you should set update the HOST but still, it will not work, as the WordPress DB configuration does not seems correct.

ENV for DB is

      MARIADB_ROOT_PASSWORD: password
      MARIADB_DATABASE: db_tyre
      MARIADB_USER: wordpress
      MARIADB_PASSWORD: wordpress

so the WordPress DB configuration should be updated and it should be db_tyre

define( 'DB_NAME', 'db_tyre');

/** MySQL database username */
define( 'DB_USER', 'wordpress');

/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress');

/** MySQL hostname */
define( 'DB_HOST', 'db:3306');

or can try with offical image

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:
Sign up to request clarification or add additional context in comments.

4 Comments

With the provided configuration, it doesn't automatically set the wp_config file?
it should work, but if there is issue then you can try with docker-compose down, as the volume keep the database persistent and new password will not effect, is there any issue still?
Yes same problem
I tried docker-compose down and i still have same problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.