1

With docker I was able to run WordPress example for docker-compose on nearly every platform, without prior docker knowledge.

I look for a way to achieve the same with Podman.
In my case, to have a fast cross-platform way to setup a working WordPress installation for development.

As Podman is far younger, a valid answer in 2022 would also be: It is not possible, because... / only possible provided constraint X.
Still I would like to create an entry point for other people, who run into the same issue in the future.

I posted my own efforts below. Before I spend more hours debugging lots of small (but still solvable) issues, I wanted to find out if someone else faced the same problem and already has a solution. If you have, please clearly document its constraints.

My particular issue, as a reference

  • I am on Ubuntu 20.04 and podman -v gives 3.4.2.
  1. docker/podman compose
  • When I use docker-compose up with Podman back-end on docker's WordPress .yml-file, I run into the "duplicate mount destination" issue.
  • podman-compose is part of Podman 4.1.0, which is not available on Ubuntu as I write this.
  1. Red Hat example
  • The example of Red Hat gives "Error establishing a database connection ... contact with the database server at mysql could not be established".
  • A solution for the above does not work for me. share is likely a typo. I tried to replace with unshare.
  1. Cent OS example
  • I found an example which uses pods instead of a docker-compose.yml file. But it is written for Cent OS.
  • I modified the Cent OS example, see the script below. I get the containers up and running. However, WordPress is unable to connect to the database.
#!/bin/bash

# Set environment variables:
DB_NAME='wordpress_db'
DB_PASS='mysupersecurepass'
DB_USER='justbeauniqueuser'
POD_NAME='wordpress_with_mariadb'
CONTAINER_NAME_DB='wordpress_db'
CONTAINER_NAME_WP='wordpress'

mkdir -P html
mkdir -P database


# Remove previous attempts
sudo podman pod rm -f $POD_NAME

# Pull before run, bc: invalid reference format eror
sudo podman pull mariadb:latest
sudo podman pull wordpress

# Create a pod instead of --link. So both containers are able to reach each others.
sudo podman pod create -n $POD_NAME -p 80:80

sudo podman run --detach --pod $POD_NAME \
-e MYSQL_ROOT_PASSWORD=$DB_PASS \
-e MYSQL_PASSWORD=$DB_PASS \
-e MYSQL_DATABASE=$DB_NAME \
-e MYSQL_USER=$DB_USER \
--name $CONTAINER_NAME_DB -v "$PWD/database":/var/lib/mysql \
docker.io/mariadb:latest

sudo podman run --detach --pod $POD_NAME \
-e WORDPRESS_DB_HOST=127.0.0.1:3306 \
-e WORDPRESS_DB_NAME=$DB_NAME \
-e WORDPRESS_DB_USER=$DB_USER \
-e WORDPRESS_DB_PASSWORD=$DB_PASS \
--name $CONTAINER_NAME_WP -v "$PWD/html":/var/www/html \
docker.io/wordpress

Also, I was a bit unsure where to post this question. If server fault or another stack exchange are a better fit, I will happily post there.

Paul Smith
  • 299
  • 2
  • 13
  • 1
    I tried combining _docker.io/library/wordpress_ and _docker.io/library/mariadb_. It seems to [work](https://github.com/containers/podman/discussions/16053#discussioncomment-3832130). Next thing I would like to try is combing _docker.io/bitnami/mariadb_ with a fedora-based wordpress, both running with `--user nonrootuser` and also using [_socket activation_](https://github.com/containers/podman/blob/main/docs/tutorials/socket_activation.md#socket-activation-of-containers). (It will probable take a while before I can find time for that) – Erik Sjölund Oct 13 '22 at 13:32

2 Answers2

3

Actually, your code works with just small changes. I removed the sudo's and changed the pods external port to 8090, instead of 80. So now everything is running as a non-root user.

#!/bin/bash
# https://stackoverflow.com/questions/74054932/how-to-install-and-setup-wordpress-using-podman

# Set environment variables:
DB_NAME='wordpress_db'
DB_PASS='mysupersecurepass'
DB_USER='justbeauniqueuser'
POD_NAME='wordpress_with_mariadb'
CONTAINER_NAME_DB='wordpress_db'
CONTAINER_NAME_WP='wordpress'

mkdir -p html
mkdir -p database

# Remove previous attempts
podman pod rm -f $POD_NAME

# Pull before run, bc: invalid reference format error
podman pull docker.io/mariadb:latest
podman pull docker.io/wordpress

# Create a pod instead of --link. 
# So both containers are able to reach each others.
podman pod create -n $POD_NAME -p 8090:80

podman run --detach --pod $POD_NAME \
-e MYSQL_ROOT_PASSWORD=$DB_PASS \
-e MYSQL_PASSWORD=$DB_PASS \
-e MYSQL_DATABASE=$DB_NAME \
-e MYSQL_USER=$DB_USER \
--name $CONTAINER_NAME_DB -v "$PWD/database":/var/lib/mysql \
docker.io/mariadb:latest

podman run --detach --pod $POD_NAME \
-e WORDPRESS_DB_HOST=127.0.0.1:3306 \
-e WORDPRESS_DB_NAME=$DB_NAME \
-e WORDPRESS_DB_USER=$DB_USER \
-e WORDPRESS_DB_PASSWORD=$DB_PASS \
--name $CONTAINER_NAME_WP -v "$PWD/html":/var/www/html \
docker.io/wordpress
tiemco
  • 76
  • 5
  • When I try it, the mariadb container crashes. Probably an unrelated issue. I will update the question, when I find out more. Can you provide your environment, so I can get a working system to start from? – Paul Smith Dec 31 '22 at 15:17
  • I'm using Ubuntu 22.04 with Podman – tiemco Jan 22 '23 at 10:36
  • 1
    I'm using Ubuntu 22.04 with Podman Version: 3.4.4 API Version: 3.4.4 Go Version: go1.17.3 Built: Thu Jan 1 01:00:00 1970 OS/Arch: linux/amd64 registries: search: - registry.access.redhat.com - docker.io – tiemco Jan 22 '23 at 10:51
  • Thanks. Then it seems like, the issue does not exist in Ubuntu 22.04 anymore. Maybe add your enviroment to your answer? I do not have the time to fix mine atm, so probably will just update to 22. Sorry @futureUbunut2004 users – Paul Smith Jan 25 '23 at 22:16
1

This is what worked for me:

#!/bin/bash
# https://stackoverflow.com/questions/74054932/how-to-install-and-setup-wordpress-using-podman

# Set environment variables:
POD_NAME='wordpress_mariadb'

DB_ROOT_PW='sup3rS3cr3t'
DB_NAME='wp'
DB_PASS='s0m3wh4tS3cr3t'
DB_USER='wordpress'

podman pod create --name $POD_NAME -p 8080:80

podman run \
-d --restart=always --pod=$POD_NAME \
-e MYSQL_ROOT_PASSWORD="$DB_ROOT_PW" \
-e MYSQL_DATABASE="$DB_NAME" \
-e MYSQL_USER="$DB_USER" \
-e MYSQL_PASSWORD="$DB_PASS" \
-v $HOME/public_html/wordpress/mysql:/var/lib/mysql:Z \
--name=wordpress-db docker.io/mariadb:latest

podman run \
-d --restart=always --pod=$POD_NAME \
-e WORDPRESS_DB_NAME="$DB_NAME" \
-e WORDPRESS_DB_USER="$DB_USER" \
-e WORDPRESS_DB_PASSWORD="$DB_PASS" \
-e WORDPRESS_DB_HOST="127.0.0.1" \
-v $HOME/public_html/wordpress/html:/var/www/html:Z \
--name wordpress docker.io/library/wordpress:latest