'Error establishing a database connection' a wordpress containerization with a pod, podman

Hello pals , don’t know what is the problems, please help me. I have read a lot of tutorial but can’t resolve the problems. I have followed this tutorial.
os: fedora workstation 36

create_blog.sh

#!/bin/bash
# create_blog.sh

set -e   #exit on most errors

podman pod create --name blog --infra --publish 8080:80 --publish 3306:3306 --network bridge
#podman pod create --name blog --infra --publish 8080:8080 

podman run --pod blog --name mariadb \
-e MARIADB_USER=chris \
-e MARIADB_PASSWORD=maGazine1! \
-e MARIADB_DATABASE=ecommerce \
-e MARIADB_ROOT_PASSWORD=maGazine1! \
--volume ./var-lib-mysql:/var/lib/mysql:Z \
-d mariadb:10.5.15

podman run --pod blog --name wordpress \
-e WORDPRESS_DB_HOST=mariadb \
-e WORDPRESS_DB_USER=chris \
-e WORDPRESS_DB_PASSWORD=maGazine1! \
-e WORDPRESS_DB_NAME=ecommerce \
--volume ./var-www-html:/var/www/html:Z \
-d wordpress:6.0.0-php7.4-apache


i have used mariadb, 127.0.0.1 as the wordpress_db_host
I have unshare the local directories:

  • podman unshare chown 999:999 -R var-lib-mysql
  • podman unshare chown 33:33 -R var-www-html

Localhost is your computer. Within a container you have your own IP.

Have a look to ip a to see what ip you got on the bridge. You can also ping mariadb to see which address responds.

I was able to solve the problem.
I think something was mesh about the podman unshare commands typed.
WordPress user in the container is root, we don’t have to set UID/GID of the local shared directory in my case var-www-html, I was using this user www-data(33) .
Then don’t do this.

podman unshare chown 33:33 -R <your-shared-directory>

I had to do this.

#reset to my UID/GID the two local shared directories.
sudo chown chris:chris -R var-*

#set the UID/GID 999 used by mariadb container in the directory /var/lib/nysql
#podman share chown 999:999 -R <your shared directory>

podman share chown 999:999 -R var-lib-mysql

After that.
run your scripts.

./create_blog.sh

go to localhost:8080, Woa that finally worked. Hurray.

1 Like