skip to Main Content

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.

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search