0

I'm having trouble deploying a Wordpress install via Docker compose/Portainer. Every time I try to deploy the docker-compose I get the following error: Error establishing a database connection on the Wordpress install.

I believe there is a mistake somewhere in the docker-compose below as I have eliminated other possibilities. It seems the WP install cannot communicate with the database volume in the container.

Any help would be appreciated, thanks

System info:

OS: Ubuntu 21.04
System: Rpi4 64bit
Docker-compose version: 1.29.2

docker-compose:

version: "3.9"
services:
        
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    container_name: wordpress
    restart: unless-stopped
    ports: # For inital setup
      - "91:80"
    security_opt:
      - no-new-privileges:true
    environment:

      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: mbA2tU9RyA5r@U
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - sbabaya:/var/www/html
      
  mariadb:
    image: mariadb:latest
    container_name: db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: mbA2tU9RyA5r@U
      MYSQL_DATABASE: wordpress
    volumes:
      - "db:/var/lib/mysql"
    logging:
      driver: "json-file"
      options:
        max-size: "10Mb"
        max-file: "5"
volumes:
  wordpress:
  db:

1 Answer 1

0

You have missed the database host - this will be the container label used in the compose file, they are automatcally setup in their own private network.

Update your environment as follows -

    environment:
      WORDPRESS_DB_HOST: wordpress-db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: mbA2tU9RyA5r@U
      WORDPRESS_DB_NAME: wordpress

Check your names, keep it simple - you might get more milage form mysql offical image (will work on arm64 as well).

This is also consistent with the offical docs here - https://hub.docker.com/_/wordpress

version: '3.1'
services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 80:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress:/var/www/html
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql
    ports:
      - 3306:3306
volumes:
  wordpress:
  db:
Sign up to request clarification or add additional context in comments.

6 Comments

I had already tested it with WORDPRESS_DB_HOST, but was still getting the same error unfortunatly.
That may be because you have also specified the container name - container_name: cuewps_sbabaya-db Try using that as the host setting.
Still getting the same issue, by using the container_name. Should I also be updating the depends_on:?
Just tried updating the depends_on, and getting the same database error.
Updated with more detail for you - really this does normally work out of the box normally...
|

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.