Home avatar

Building and implementing end-to-end solutions to solve real-world problems

How to Backup and Restore WordPress With Docker Compose

In this guide, we will walk you through the process of creating scripts to backup and restore a WordPress website running in Docker Compose. These scripts will help you safeguard your WordPress data and quickly restore it if needed.

Backup WordPress Volumes

Step 1: Create a Backup Script

First, you need to create a backup script. This script will use the futurice/docker-volume-backup Docker image to back up the volumes associated with your WordPress and MariaDB containers.

Trim the Whitespace Characters From a Bash Variable

In Bash, you can trim whitespace characters from a variable using various methods, as shown in your code. Here’s a breakdown of the different approaches:

  1. Remove Leading and Trailing White Spaces:

    1
    2
    
    NEW_VARIABLE="$(echo -e "${VARIABLE_NAME}" | tr -d '[:space:]')"
    # NEW_VARIABLE='aaa  bbb'

    This method uses the tr command to delete all whitespace characters, both leading and trailing, in the variable VARIABLE_NAME.

How to Change WordPress Site URL With WP-CLI

If you need to change the domain URL of your WordPress site, you can use WP-CLI, a powerful command-line tool for managing WordPress. Changing the site URL is a common task, especially when migrating your site to a new domain. Here’s a step-by-step guide on how to do it with WP-CLI.

1. Backup Your WordPress Database

Before making any changes, it’s crucial to create a backup of your WordPress database. This ensures that you can restore your site if anything goes wrong during the URL change process.

Accessing Windows or Mac Host IP in Docker

When working with Docker containers on Windows or Mac, you might need to access the IP address of the host machine from within the container. Docker provides two convenient DNS names that you can use to achieve this: host.docker.internal and gateway.docker.internal.

Using host.docker.internal

The DNS name host.docker.internal allows you to access the IP address of the host machine from within a Docker container. This is particularly useful when you need to communicate with services running on the host, such as a development server.

Whatsapp Webjs Wont Reconnect After Macbook Sleep

You’re facing an issue with the whatsapp-web.js library when trying to reconnect after your MacBook goes to sleep. The solution you’ve provided involves using a remote browser via Docker to run Chrome and then connecting whatsapp-web.js to it using the browserWSEndpoint option. This is a workaround to ensure that the connection is maintained even after your MacBook wakes up from sleep mode.

Here’s a breakdown of the steps and code you’ve provided:

Docker Compose Docker-Compose-Yml Command Multiline

Sure! The provided code snippet is meant to modify the Tomcat server information displayed when the server starts up. This can be achieved using Docker Compose by modifying the docker-compose.yml file as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
version: '3'
services:
  tomcat:
    image: tomcat:latest
    ports:
      - "8080:8080"
    command: >
      bash -c "mkdir -p /usr/local/tomcat/lib/org/apache/catalina/util/ &&
      echo server.info=PlantUML > /usr/local/tomcat/lib/org/apache/catalina/util/ServerInfo.properties &&
      catalina.sh run"

In this Docker Compose configuration: