WordPress Docker Compose wordpress cli error establishing a database connection

  docker, docker-compose, wordpress

I am using this repo https://github.com/nezhar/wordpress-docker-compose for the docker-compose setup.

Here is the docker-compose.yml :

version: '3'

services:
  wp:
    image: wordpress:latest # https://hub.docker.com/_/wordpress/
    ports:
      - ${IP}:80:80 # change ip if required
    volumes:
      - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html # Full wordpress project
      #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development
      #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: "${DB_NAME}"
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}"
    depends_on:
      - db
    links:
      - db

  wpcli:
    image: wordpress:cli
    volumes:
      - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html
    depends_on:
      - db
      - wp

  pma:
    image: phpmyadmin/phpmyadmin
    environment:
      # https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables
      PMA_HOST: db
      PMA_PORT: 3306
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
    ports:
      - ${IP}:8080:80
    links:
      - db:db

  db:
    image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
    ports:
      - ${IP}:3306:3306 # change ip if required
    command: [
        '--default_authentication_plugin=mysql_native_password',
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_unicode_ci'
    ]
    volumes:
      - ./wp-data:/docker-entrypoint-initdb.d
      - db_data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: "${DB_NAME}"
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"

volumes:
  db_data:

The wordpress, db and pma containere are working ok but the wpcli exits in a few seconds with the following error :

wpcli_1 | Error: Error establishing a database connection.
wordpress_wpcli_1 exited with code 1

I tried to start the cli container later but the result is the same.

Creating wordpress_db_1 ... done
Creating wordpress_pma_1 ... done
Creating wordpress_wp_1  ... done
Creating wordpress_wpcli_1 ... done
Attaching to wordpress_db_1, wordpress_pma_1, wordpress_wp_1, wordpress_wpcli_1
db_1     | 2021-05-04 12:06:33+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.24-1debian10 started.
db_1     | 2021-05-04 12:06:33+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1     | 2021-05-04 12:06:33+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.24-1debian10 started.
db_1     | 2021-05-04 12:06:33+00:00 [Note] [Entrypoint]: Initializing database files
db_1     | 2021-05-04T12:06:33.320675Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.24) initializing of server in progress as process 41
db_1     | 2021-05-04T12:06:33.325664Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db_1     | 2021-05-04T12:06:33.934687Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db_1     | 2021-05-04T12:06:35.263098Z 6 [Warning] [MY-010453] [Server] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.
pma_1    | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
pma_1    | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
pma_1    | [Tue May 04 12:06:36.206734 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.16 configured -- resuming normal operations
pma_1    | [Tue May 04 12:06:36.207373 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
wp_1     | WordPress not found in /var/www/html - copying now...
db_1     | 2021-05-04 12:06:38+00:00 [Note] [Entrypoint]: Database files initialized
db_1     | 2021-05-04 12:06:38+00:00 [Note] [Entrypoint]: Starting temporary server
wpcli_1  | Error: This does not seem to be a WordPress installation.
wpcli_1  | Pass --path=`path/to/wordpress` or run `wp core download`.
wordpress_wpcli_1 exited with code 1
db_1     | 2021-05-04T12:06:39.229503Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.24) starting as process 86
db_1     | 2021-05-04T12:06:39.249635Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db_1     | 2021-05-04T12:06:39.566784Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db_1     | 2021-05-04T12:06:39.719458Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
db_1     | 2021-05-04T12:06:39.849538Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1     | 2021-05-04T12:06:39.849747Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
db_1     | 2021-05-04T12:06:39.852272Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1     | 2021-05-04T12:06:39.868659Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
db_1     | 2021-05-04 12:06:39+00:00 [Note] [Entrypoint]: Temporary server started.
db_1     | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1     | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
db_1     | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1     | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db_1     | 2021-05-04 12:06:43+00:00 [Note] [Entrypoint]: Creating database wordpress
db_1     |
db_1     | 2021-05-04 12:06:43+00:00 [Note] [Entrypoint]: Stopping temporary server
db_1     | 2021-05-04T12:06:43.235898Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.24).
db_1     | 2021-05-04T12:06:44.859847Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
db_1     | 2021-05-04 12:06:45+00:00 [Note] [Entrypoint]: Temporary server stopped
db_1     |
db_1     | 2021-05-04 12:06:45+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db_1     |
db_1     | 2021-05-04T12:06:45.501859Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.24) starting as process 1
db_1     | 2021-05-04T12:06:45.511466Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db_1     | 2021-05-04T12:06:45.768449Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db_1     | 2021-05-04T12:06:45.867756Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
db_1     | 2021-05-04T12:06:45.950266Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1     | 2021-05-04T12:06:45.950428Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
db_1     | 2021-05-04T12:06:45.954248Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1     | 2021-05-04T12:06:45.975867Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
wp_1     | Complete! WordPress has been successfully copied to /var/www/html
wp_1     | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER)
wp_1     | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
wp_1     | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
wp_1     | [Tue May 04 12:06:49.596979 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.18 configured -- resuming normal operations
wp_1     | [Tue May 04 12:06:49.597162 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
wpcli_1  | Error: Error establishing a database connection.
wordpress_wpcli_1 exited with code 1
wpcli_1  | Error: Error establishing a database connection.
wordpress_wpcli_1 exited with code 

What could be the problem ?

Source: Docker Questions

LEAVE A COMMENT