浏览代码

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
   # 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
   && cp mautrix_instagram/example-config.yaml . && rm -rf mautrix_instagram
 
 
+ENV UID=1337 GID=1337
 VOLUME /data
 VOLUME /data
 
 
 CMD ["/opt/mautrix-instagram/docker-run.sh"]
 CMD ["/opt/mautrix-instagram/docker-run.sh"]

+ 10 - 1
docker-run.sh

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