Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uatschitchun/e5cf4cf605d4b713082a9ea091930d90 to your computer and use it in GitHub Desktop.
Save Uatschitchun/e5cf4cf605d4b713082a9ea091930d90 to your computer and use it in GitHub Desktop.
This allows to set JAVA memory settings & environment variables within docker-compose.yml

With said Docker Container from: https://hub.docker.com/r/fionnb/picapport it sadly isn't possible to set JAVA memory options.

The Docker starts up picapport with running pa-start.sh. So I copied that script from inside the Container and (very dirty!) adapted it to be able to set -XX:MaxDirectMemorySize=2048m -Xms256m -Xmx1024m to one's own liking.

The diff to the original is added below.

For to make this work, create the docker-compose.yml & pa-start.sh inside the same folder and make pa-start.sh executeable with chmod +x pa-start.sh

Adjust the docker-compose.yml to your own setup and start up with docker-compose up -d

What this compose does is, it replaces the container's own pa-start.sh which is located in /opt/picapport/ with the changed one as a volume ./pa-start.sh:/opt/picapport/pa-start.sh making it possible to set PICAPPORT_PORT, PICAPPORT_LANG and JAVA_OPTS from within docker-compose.yml without the need of creating an ENV file as stated on the docker hub's description.

version: '3'
services:
picapport:
image: fionnb/picapport:latest
container_name: picapport
hostname: picapport
restart: unless-stopped
user: 1000:100 # should be owner of volumes
ports:
- 8888:8888
environment:
- TZ=Europe/Berlin
- PICAPPORT_LANG=de
# PICAPPORT_PORT is only read & set on very first start of container!!!
# changing port afterwards needs to be done in picapport.properties
- PICAPPORT_PORT=8888
# Default values: -XX:MaxDirectMemorySize=3954m -Xms2048m -Xmx2048m
- JAVA_OPTS=-XX:MaxDirectMemorySize=2048m -Xms256m -Xmx1024m
- LANG=C.UTF-8
volumes:
- ./pa-start.sh:/opt/picapport/pa-start.sh
- /path/to/data:/opt/picapport/data
- /path/to/images:/opt/picapport/photos:ro
#!/bin/bash
#PICAPPORT_PORT="$1"
#PICAPPORT_LANG="$2"
CONFIG="data/picapport.properties"
#if [ -f "data/ENV" ]; then
# echo "--- READING ENV ---"
# source data/ENV
#fi
# installs a minimal config if there is none present
[ ! -f "$CONFIG" ] && printf "%s\n%s\n%s\n" "server.port=$PICAPPORT_PORT" "robot.root.0.path=/opt/picapport/photos" "foto.jpg.usecache=2" > "$CONFIG"
# default lang is german
[ -z "$PICAPPORT_LANG" ] && PICAPPORT_LANG="de"
# this tries to upgrade older data to the correct uid
[ $(find data/picapport.ks -uid 0 | wc -l ) -gt 0 ] && \
echo "WARNING: to upgrade to this container version, you need change ownership of files: chown -R $UID data photos/uploads >/dev/null 2>&1" && \
exit 0
function clean_up {
echo "shutting down..."
killall java
wait %1
echo "shutdown complete."
exit
}
trap clean_up SIGHUP SIGINT SIGTERM
echo "starting picapport process..."
#java -Duser.home=/opt/picapport -Duser.language="$PICAPPORT_LANG" -Dpicapport.directory=data -XX:MaxDirectMemorySize=2048m -Xms1024m -Xmx1024m -Dstorage.diskCache.bufferSize=512 -jar picapport-headless.jar -configfile="$CONFIG" -pgui.enabled=false &
java -Duser.home=/opt/picapport -Duser.language="$PICAPPORT_LANG" -Dpicapport.directory=data $JAVA_OPTS -Dstorage.diskCache.bufferSize=512 -jar picapport-headless.jar -configfile="$CONFIG" -pgui.enabled=false &
while true; do sleep 1; done # wait for shutdown signals
--- pa-start.sh.orig 2021-04-29 17:48:27.001651588 +0200
+++ pa-start.sh 2021-04-29 17:40:22.771537799 +0200
@@ -1,13 +1,13 @@
#!/bin/bash
-PICAPPORT_PORT="$1"
-PICAPPORT_LANG="$2"
+#PICAPPORT_PORT="$1"
+#PICAPPORT_LANG="$2"
CONFIG="data/picapport.properties"
-if [ -f "data/ENV" ]; then
- echo "--- READING ENV ---"
- source data/ENV
-fi
+#if [ -f "data/ENV" ]; then
+# echo "--- READING ENV ---"
+# source data/ENV
+#fi
# installs a minimal config if there is none present
[ ! -f "$CONFIG" ] && printf "%s\n%s\n%s\n" "server.port=$PICAPPORT_PORT" "robot.root.0.path=/opt/picapport/photos" "foto.jpg.usecache=2" > "$CONFIG"
@@ -32,6 +32,7 @@
echo "starting picapport process..."
-java -Duser.home=/opt/picapport -Duser.language="$PICAPPORT_LANG" -Dpicapport.directory=data -XX:MaxDirectMemorySize=3954m -Xms2048m -Xmx2048m -Dstorage.diskCache.bufferSize=512 -jar picapport-headless.jar -configfile="$CONFIG" -pgui.enabled=false &
+#java -Duser.home=/opt/picapport -Duser.language="$PICAPPORT_LANG" -Dpicapport.directory=data -XX:MaxDirectMemorySize=2048m -Xms1024m -Xmx1024m -Dstorage.diskCache.bufferSize=512 -jar picapport-headless.jar -configfile="$CONFIG" -pgui.enabled=false &
+java -Duser.home=/opt/picapport -Duser.language="$PICAPPORT_LANG" -Dpicapport.directory=data $JAVA_OPTS -Dstorage.diskCache.bufferSize=512 -jar picapport-headless.jar -configfile="$CONFIG" -pgui.enabled=false &
while true; do sleep 1; done # wait for shutdown signals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment