Using an External PostgreSQL Database for ThingWorx Docker
The following example is a Docker Compose file for PostgreSQL that uses an external database:
For information on setting up your PostgreSQL Server database and schema in external cases, refer to Installing ThingWorx.
For ThingWorx 9.0 and 9.1: 
version: '2.2'

# Note, this example includes a _blank_ postgreSQL docker image for demonstration
# purposes. The postgresql service should be removed and DATABASE_HOST should point
# to the production database either with a DNS name, or IP.

services:
postgresql:
image: postgres:9.4
ports:
- "5432"
healthcheck:
test: pg_isready -U postgres
interval: 15s
environment:
# NOTE: You must manually set a default postgres password if using this
# example for testing.
- "POSTGRES_PASSWORD="
volumes:
- "./thingworx-postgres-storage/postgres-data:/var/lib/postgresql/data"

platform:
image: thingworx/platform-postgres:latest
healthcheck:
test: curl -s -w '%{http_code}' -U 'bad:creds'
localhost:8080/Thingworx/Subsystems/PlatformSubsystem | grep -w 401
interval: 15s
depends_on:
postgresql:
condition: service_healthy
ports:
- "8080:8080"
- "8443:8443"
environment:
- "ENABLE_CLUSTERED_MODE=false"
- "INITIAL_HEAP=2"
- "MAX_HEAP=4"
- "DATABASE_HOST=postgresql"
- "DATABASE_PORT=5432"
- "TWX_DATABASE_USERNAME=thingworx"
- "TWX_DATABASE_SCHEMA=thingworx"
# NOTE: TWX_DATABASE_PASSWORD must be set for your environment manually.
- "TWX_DATABASE_PASSWORD="
- "ENABLE_HTTP=true"
- "ENABLE_HTTPS=false"
# NOTE: If supplying a keystore for SSL, you must set your keystore password
#- "SSL_KEYSTORE_PASSWORD="
- "DATABASE_ADMIN_USERNAME=postgres"
# NOTE: DATABASE_ADMIN_PASSWORD should match your environment or POSTGRES_PASSWORD
# if using above service for testing.
- "DATABASE_ADMIN_PASSWORD="
- "TABLESPACE_LOCATION=/var/lib/postgresql/data"
volumes:
- "./thingworx-postgres-storage/ThingworxPlatform:/ThingworxPlatform"
- "./thingworx-postgres-storage/ThingworxStorage:/ThingworxStorage"
- "./thingworx-postgres-storage/ThingworxBackupStorage:/ThingworxBackupStorage"
- "./thingworx-postgres-storage/tomcat-logs:/opt/apache-tomcat/logs"
For ThingWorx 9.2: 
version: '2.2'

# Note, this example includes a _blank_ postgreSQL docker image for demonstration
# purposes. The postgresql service should be removed and DATABASE_HOST should point
# to the production database either with a DNS name, or IP.

services:
postgresql:
image: postgres:9.4
ports:
- "5432"
healthcheck:
test: pg_isready -U postgres
interval: 15s
environment:
# NOTE: You must manually set a default postgres password if using this
# example for testing.
- "POSTGRES_PASSWORD="
volumes:
- "./thingworx-postgres-storage/postgres-data:/var/lib/postgresql/data"

postgresql-init:
image: thingworx/postgresql-init-twx:latest
entrypoint: bash -c -x "/usr/local/bin/db-check.sh && /usr/local/bin/db-setup.sh && sleep infinity"
healthcheck:
test: [ "CMD-SHELL", "grep 'success' tmp/status.txt || exit 1" ]
interval: 15s
retries: 5
depends_on:
postgresql:
condition: service_healthy
environment:
# NOTE: Set DATABASE_ADMIN_USERNAME, DATABASE_ADMIN_PASSWORD DATABASE_ADMIN_SCHEMA for connecting
# to the postgres as super user
- "DATABASE_ADMIN_USERNAME="
- "DATABASE_ADMIN_PASSWORD="
- "DATABASE_ADMIN_SCHEMA="
- "DATABASE_HOST=postgresql"
- "DATABASE_PORT=5432"
- "TWX_DATABASE_USERNAME="
- "TWX_DATABASE_SCHEMA="
- "TWX_DATABASE_PASSWORD="
- "TABLESPACE_LOCATION=/var/lib/postgresql/data"

platform:
image: thingworx/platform-postgres:latest
healthcheck:
test: curl -f localhost:8080/Thingworx/health
interval: 15s
depends_on:
postgresql-init:
condition: service_healthy
ports:
- "8080:8080"
- "8443:8443"
environment:
- "INITIAL_HEAP=2"
- "MAX_HEAP=4"
- "DATABASE_HOST=postgresql"
- "DATABASE_PORT=5432"
- "TWX_DATABASE_USERNAME=thingworx"
- "TWX_DATABASE_SCHEMA=thingworx"
# NOTE: TWX_DATABASE_PASSWORD for postgresql platform must be set to match your
# environment.
- "TWX_DATABASE_PASSWORD="
- "ENABLE_HTTP=true"
- "ENABLE_HTTPS=false"
# NOTE: If supplying a keystore for SSL, you must set your keystore password
#- "SSL_KEYSTORE_PASSWORD="
volumes:
- "./thingworx-postgres-storage/ThingworxPlatform:/ThingworxPlatform"
- "./thingworx-postgres-storage/ThingworxStorage:/ThingworxStorage"
- "./thingworx-postgres-storage/ThingworxBackupStorage:/ThingworxBackupStorage"
- "./thingworx-postgres-storage/tomcat-logs:/app/opt/apache-tomcat/logs"
For ThingWorx 9.3 and Later: 
version: '2.2'

# Note, this example includes a _blank_ postgreSQL docker image for demonstration
# purposes. The postgresql service should be removed and DATABASE_HOST should point
# to the production database either with a DNS name, or IP.

services:
postgresql:
image: postgres:9.4
ports:
- "5432"
healthcheck:
test: pg_isready -U postgres
interval: 15s
environment:
# NOTE: You must manually set a default postgres password if using this
# example for testing.
- "POSTGRES_PASSWORD="
volumes:
- "./thingworx-postgres-storage/postgres-data:/var/lib/postgresql/data"

postgresql-init:
image: thingworx/postgresql-init-twx:latest
entrypoint: bash -c -x "/usr/local/bin/db-check.sh && /usr/local/bin/db-setup.sh && sleep infinity"
healthcheck:
test: [ "CMD-SHELL", "grep 'success' tmp/status.txt || exit 1" ]
interval: 15s
retries: 5
depends_on:
postgresql:
condition: service_healthy
environment:
# NOTE: Set DATABASE_ADMIN_USERNAME, DATABASE_ADMIN_PASSWORD DATABASE_ADMIN_SCHEMA for connecting
# to the postgres as super user
- "DATABASE_ADMIN_USERNAME="
- "DATABASE_ADMIN_PASSWORD="
- "DATABASE_ADMIN_SCHEMA="
- "DATABASE_HOST=postgresql"
- "DATABASE_PORT=5432"
- "TWX_DATABASE_USERNAME="
- "TWX_DATABASE_SCHEMA="
- "TWX_DATABASE_PASSWORD="
- "TABLESPACE_LOCATION=/var/lib/postgresql/data"
security-cli:
image: thingworx/security-tool:latest
entrypoint: sh -c "/opt/docker-entrypoint.sh && sleep infinity"
healthcheck:
test: [ "CMD-SHELL", "grep 'success' status.txt || exit 1" ]
interval: 15s
retries: 5
environment:
KEYSTORE: 'true'
# NOTE: Set KEYSTORE_PASSWORD (Must match value from platform container)
KEYSTORE_PASSWORD: 'thingworxthingworx'
KEYSTORE_PASSWORD_FILE_PATH: '/opt'
KEYSTORE_FILE_PATH: '/ThingworxStorage'
CUSTOM_SECRET_LIST: 'encrypt.db.password:TWX_DATABASE_PASSWORD'
# NOTE: Set TWX_DATABASE_PASSWORD
TWX_DATABASE_PASSWORD: 'thingworx'
volumes:
- "./ThingworxStorage:/ThingworxStorage"
platform:
image: thingworx/platform-postgres:latest
healthcheck:
test: curl -f localhost:8080/Thingworx/health
interval: 15s
depends_on:
postgresql-init:
condition: service_healthy
ports:
- "8080:8080"
- "8443:8443"
environment:
- "INITIAL_HEAP=2"
- "MAX_HEAP=4"
- "DATABASE_HOST=postgresql"
- "DATABASE_PORT=5432"
- "TWX_DATABASE_USERNAME=thingworx"
- "TWX_DATABASE_SCHEMA=thingworx"
# NOTE: TWX_DATABASE_PASSWORD for postgresql platform must be set to match your
# environment.
- "TWX_DATABASE_PASSWORD="
- "ENABLE_HTTP=true"
- "ENABLE_HTTPS=false"
# NOTE: If supplying a keystore for SSL, you must set your keystore password
#- "SSL_KEYSTORE_PASSWORD="
volumes:
- "./thingworx-postgres-storage/ThingworxPlatform:/ThingworxPlatform"
- "./thingworx-postgres-storage/ThingworxStorage:/ThingworxStorage"
- "./thingworx-postgres-storage/ThingworxBackupStorage:/ThingworxBackupStorage"
- "./thingworx-postgres-storage/tomcat-logs:/app/opt/apache-tomcat/logs"
Was this helpful?