Переглянути джерело

Don't run as root in docker image

Tulir Asokan 3 роки тому
батько
коміт
263cbef9ac
2 змінених файлів з 11 додано та 1 видалено
  1. 1 0
      Dockerfile
  2. 10 1
      docker-run.sh

+ 1 - 0
Dockerfile

@@ -39,6 +39,7 @@ RUN apk add git && pip3 install .[all] && apk del git \
   # This doesn't make the image smaller, but it's needed so that the `version` command works properly
   && cp mautrix_instagram/example-config.yaml . && rm -rf mautrix_instagram
 
+ENV UID=1337 GID=1337
 VOLUME /data
 
 CMD ["/opt/mautrix-instagram/docker-run.sh"]

+ 10 - 1
docker-run.sh

@@ -1,4 +1,10 @@
 #!/bin/sh
+
+# Define functions.
+function fixperms {
+	chown -R $UID:$GID /data
+}
+
 cd /opt/mautrix-instagram
 
 if [ ! -f /data/config.yaml ]; then
@@ -7,12 +13,15 @@ if [ ! -f /data/config.yaml ]; then
 	echo "Copied default config file to /data/config.yaml"
 	echo "Modify that config file to your liking."
 	echo "Start the container again after that to generate the registration file."
+	fixperms
 	exit
 fi
 
 if [ ! -f /data/registration.yaml ]; then
 	python3 -m mautrix_instagram -g -c /data/config.yaml -r /data/registration.yaml
+	fixperms
 	exit
 fi
 
-exec python3 -m mautrix_instagram -c /data/config.yaml
+fixperms
+exec su-exec $UID:$GID python3 -m mautrix_instagram -c /data/config.yaml