Script for deploying the docker4wordpress project

  bash, docker, wp-cli

I’m writing my own bash script which will download the latest version of docker4wordpress and also deploy the project (create a user, delete unnecessary plugins, themes, etc.).

get_latest_release() {
  curl --silent "https://api.github.com/repos/$1/releases/latest" | grep -Po '"tag_name": "K.*?(?=")'
}

createwp()
{
  wp_tar=$(get_latest_release wodby/docker4wordpress)
  git clone --depth 1 --branch $wp_tar https://github.com/wodby/docker4wordpress.git
  cd docker4wordpress/
  rm -rf .git/
  docker-compose up -d
  docker container exec my_wordpress_project_php wp core install 
                                                       --url=http://wp.docker.localhost:8000 
                                                       --title=TEST 
                                                       --admin_user=Vitalik 
                                                       --admin_password=111 
                                                       --admin_email='[email protected]'
  docker container exec my_wordpress_project_php wp plugin uninstall hello akismet 
  docker container exec my_wordpress_project_php wp theme delete twentynineteen twentytwenty
  docker container exec my_wordpress_project_php wp user update 1 --show_admin_bar_front=false --admin_color=midnight
  echo "Your site run in http://wp.docker.localhost:8000"
}

After creating all containers, I will get the following error:

Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at mariadb. This could mean your host’s database server is down.
Error: Error establishing a database connection.

As far as I understand, the commands wp cli are executed when the database container is not yet created.

I tried to get the docker-compose process id and wait for it to complete, but it doesn’t work.

docker-compose up -d
pid=$!
wait $pid
docker ...

Source: Docker Questions

LEAVE A COMMENT