Restore Dataset Using Docker

Last Updated: Dec 9, 2022
documentation for the dotCMS Content Management System

These steps will help as a guide to restore dotCMS dataset (database and assets) using docker compose, on local machine for testing purposes.

Please note also that versions 22.02 and later include a simple menu button for exporting assets and database dumps.

1. Install Docker

To install Docker, follow the steps here: https://docs.docker.com/engine/install/

In most cases, the easiest approach is to install Docker Desktop, though Linux servers may instead opt for one of the packages in the Server section.

a. Install Docker Compose

If you installed Docker Desktop in Step 1, this is already installed. Otherwise, follow the steps here: https://docs.docker.com/compose/install/

2. Create docker-compose File

Copy this docker-compose.yml file to use as an example; change as needed.

version: '3.5'

networks:
  db_net:
  es_net:

volumes:
  cms-shared:
  dbdata:
  esdata:

services:
################################################################################
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
    environment:
      - cluster.name=elastic-cluster
      - discovery.type=single-node
      - data
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xmx3G "
    ports:
      - 9200:9200
      - 9600:9600
    volumes:
      - esdata:/usr/share/elasticsearch/data
    networks:
      - es_net
################################################################################
  dotcms: 
    image: dotcms/dotcms:22.03_lts

    environment:
      "CATALINA_OPTS": '-Xmx1g '
      "DB_BASE_URL": "jdbc:postgresql://db/dotcms"
      "DB_USERNAME": 'dotcmsdbuser'
      "DB_PASSWORD": 'password'
      "DOT_ES_AUTH_BASIC_PASSWORD": 'admin'
      "DOT_ES_ENDPOINTS": 'http://elasticsearch:9200'
      "DOT_INITIAL_ADMIN_PASSWORD": 'admin'
    depends_on:
      - db
      - elasticsearch
    volumes:
      - cms-shared:/data/shared
    networks:
      - db_net
      - es_net
    ports:
      - "8082:8082"
      - "8443:8443"
################################################################################
  db:
    image: dotcms/postgres:15
    command: postgres -c 'max_connections=400' -c 'shared_buffers=512MB' -c 'effective_cache_size=1536MB' -c 'maintenance_work_mem=128MB'
    environment:
        "POSTGRES_USER": 'dotcmsdbuser'
        "POSTGRES_PASSWORD": 'db_pass'
        "POSTGRES_DB": 'dotcms'
    networks:
      - db_net
    volumes:
      - dbdata:/var/lib/postgresql/data
    restart: "unless-stopped"
    ports:
      - "5432:5432"

3. Create Directories

a. Base Directories

Create the directory paths shared and logs on the same path that the docker-compose.yml file will read from:

mkdir shared logs

b. Asset Directories

Next, create an assets directory under the shared path like this: ./shared/assets/ and place the assets from your dataset on that folder.

4. Move Plugins

If there are any Dynamic Plugins (OSGi), place them in the ./shared/felix/load/ directory.

Any undeployed OSGi plugins should be moved to ./shared/felix/undeployed/

5. Adjust Folder Permissions

Change the permissions on the shared and logs paths to userid and groupid 65001, which is the userid that dotCMS runs inside the container:

sudo chown -R 65001.65001 shared
sudo chown -R 65001.65001 logs

This should result in something like the following:

dotcms-standalone $ ls -lha 
total 20K
drwxrwxr-x 4 dotcmsuser     dotcmsuser     4.0K Jan  8 14:31 .
drwxrwxr-x 4 dotcmsuser     dotcmsuser     4.0K Jan  7 08:46 ..
-rw-rw-r-- 1 dotcmsuser     dotcmsuser     1.7K Jan  7 14:43 docker-compose.yml
drwxrwxr-x 2 65001          65001          4.0K Jan  8 14:31 logs
drwxrwxr-x 2 65001          65001          4.0K Jan  8 14:31 shared

6. Start the DB Container

For now, just start the DB container to restore the database (use -d to run it as daemon):

docker compose up db

7. Restore Database

Restore the database by connecting with the credentials on the docker-compose.yml file, similar to restoring any other database dump in Postgresql:

psql -U dotcmsdbuser dotcms -h localhost

Enter your password when prompted, and then use:

dotcms=# \i dotcms-prod-restore.sql

8. Stop the Database Container

Stop the docker compose with stop or control + c, if it was not running as daemon.

docker compose stop

9. Reinitialize and Reindex

Start docker compose with all the services (use -d to run it as daemon):

docker compose up -d

At this point, you should be able to access your dotCMS instance running with the restored dataset by accessing http://localhost:8082 in the browser. To conclude the restoration process, simply complete a full reindex of content.

Please note that this has been an example presented for testing purposes, and as such is simpler than a typical production environment.

On this page

×

We Dig Feedback

Selected excerpt:

×