torrust / torrust-index

This repository serves as the backend for the Torrust Index project.
https://torrust.com
GNU Affero General Public License v3.0
54 stars 19 forks source link

Docs: Command to run app with docker doesn't work #739

Closed josecelano closed 1 month ago

josecelano commented 1 month ago

Parent issue: https://github.com/torrust/torrust-index/issues/738 Source: https://docs.rs/torrust-index/latest/torrust_index/index.html#run-with-docker

mkdir -p ./storage/database \
  && export USER_ID=1000 \
  && docker run -it \
    --user="$USER_ID" \
    --publish 3001:3001/tcp \
    --volume "$(pwd)/storage":"/app/storage" \
    torrust/index
+ '[' -z 1000 ]
+ adduser --disabled-password --shell /bin/sh --uid 1000 torrust
adduser: permission denied (are you root?)
+ mkdir -p /var/lib/torrust/index/database/ /etc/torrust/index/
mkdir: can't create directory '/var/lib/torrust/index/database/': Permission denied
+ chown -R 1000 /var/lib/torrust /var/log/torrust /etc/torrust
chown: /var/lib/torrust/index: Operation not permitted
chown: /var/lib/torrust/index: Operation not permitted
chown: /var/lib/torrust: Operation not permitted
chown: /var/lib/torrust: Operation not permitted
chown: /var/log/torrust/index: Operation not permitted
chown: /var/log/torrust/index: Operation not permitted
chown: /var/log/torrust: Operation not permitted
chown: /var/log/torrust: Operation not permitted
chown: /etc/torrust/index: Operation not permitted
chown: /etc/torrust/index: Operation not permitted
chown: /etc/torrust: Operation not permitted
chown: /etc/torrust: Operation not permitted
+ chmod -R 2770 /var/lib/torrust /var/log/torrust /etc/torrust
chmod: /var/lib/torrust: Operation not permitted
chmod: /var/lib/torrust: Operation not permitted
chmod: /var/log/torrust: Operation not permitted
chmod: /var/log/torrust: Operation not permitted
chmod: /etc/torrust: Operation not permitted
chmod: /etc/torrust: Operation not permitted
+ '[' -n sqlite3 ]
+ cmp_lc sqlite3 sqlite3
+ clean sqlite3
+ echo sqlite3
+ tr -d -c a-zA-Z0-9-
+ to_lc sqlite3
+ echo sqlite3
+ tr '[:upper:]' '[:lower:]'
+ clean sqlite3
+ echo sqlite3
+ tr -d -c a-zA-Z0-9-
+ to_lc sqlite3
+ echo sqlite3
+ tr '[:upper:]' '[:lower:]'
+ '[' sqlite3 '=' sqlite3 ]
+ default_database=/usr/share/torrust/default/database/index.sqlite3.db
+ default_config=/usr/share/torrust/default/config/index.container.sqlite3.toml
+ install_config=/etc/torrust/index/index.toml
+ install_database=/var/lib/torrust/index/database/sqlite3.db
+ inst /usr/share/torrust/default/config/index.container.sqlite3.toml /etc/torrust/index/index.toml
+ '[' -n /usr/share/torrust/default/config/index.container.sqlite3.toml ]
+ '[' -n /etc/torrust/index/index.toml ]
+ '[' -e /usr/share/torrust/default/config/index.container.sqlite3.toml ]
+ '[' '!' -e /etc/torrust/index/index.toml ]
+ install -D -m 0640 -o torrust -g torrust /usr/share/torrust/default/config/index.container.sqlite3.toml /etc/torrust/index/index.toml
install: unknown user torrust
+ inst /usr/share/torrust/default/database/index.sqlite3.db /var/lib/torrust/index/database/sqlite3.db
+ '[' -n /usr/share/torrust/default/database/index.sqlite3.db ]
+ '[' -n /var/lib/torrust/index/database/sqlite3.db ]
+ '[' -e /usr/share/torrust/default/database/index.sqlite3.db ]
+ '[' '!' -e /var/lib/torrust/index/database/sqlite3.db ]
+ install -D -m 0640 -o torrust -g torrust /usr/share/torrust/default/database/index.sqlite3.db /var/lib/torrust/index/database/sqlite3.db
install: unknown user torrust
+ cmp_lc release runtime
+ clean release
+ echo release
+ tr -d -c a-zA-Z0-9-
+ to_lc release
+ echo release
+ tr '[:upper:]' '[:lower:]'
+ clean runtime
+ echo runtime
+ tr -d -c a-zA-Z0-9-
+ to_lc runtime
+ echo runtime
+ tr '[:upper:]' '[:lower:]'
+ '[' release '=' runtime ]
+ cmp_lc release debug
+ clean release
+ echo release
+ tr -d -c a-zA-Z0-9-
+ to_lc release
+ echo release
+ tr '[:upper:]' '[:lower:]'
+ clean debug
+ echo debug
+ tr -d -c a-zA-Z0-9-
+ to_lc debug
+ echo debug
+ tr '[:upper:]' '[:lower:]'
+ '[' release '=' debug ]
+ cmp_lc release release
+ clean release
+ echo release
+ tr -d -c a-zA-Z0-9-
+ to_lc release
+ echo release
+ tr '[:upper:]' '[:lower:]'
+ clean release
+ echo release
+ tr -d -c a-zA-Z0-9-
+ to_lc release
+ echo release
+ tr '[:upper:]' '[:lower:]'
+ '[' release '=' release ]
/usr/local/bin/entry.sh: line 66: can't create /etc/motd: Permission denied
+ '[' -e /usr/share/torrust/container/message ]
/usr/local/bin/entry.sh: line 72: can't create /etc/motd: Permission denied
+ chmod 0644 /etc/motd
chmod: /etc/motd: No such file or directory
/usr/local/bin/entry.sh: line 77: can't create /etc/profile: Permission denied
+ cd /home/torrust
/usr/local/bin/entry.sh: cd: line 79: can't cd to /home/torrust: No such file or directory
+ exit 1
josecelano commented 1 month ago

The new docker configuration requires executing the container as root. We can't pass this argument: --user="$USER_ID" \.

cd /tmp \
  && mkdir torrust-index \
  && cd torrust-index \
  && export USER_ID=1000 \
  && docker run -it \
    --env USER_ID="$USER_ID" \
    --publish 3001:3001/tcp \
    --volume "$(pwd)/storage/index/lib":"/var/lib/torrust/index" \
    --volume "$(pwd)/storage/index/log":"/var/log/torrust/index" \
    --volume "$(pwd)/storage/index/etc":"/etc/torrust/index" \
    torrust/index:develop

You can also create the needed folder manually:

cd /tmp \
  && mkdir torrust-index \
  && cd torrust-index \
  && mkdir -p ./storage/index/lib/database \
  && mkdir -p ./storage/index/log \
  && mkdir -p ./storage/index/etc \
  && sqlite3 "./storage/index/lib/database/sqlite3.db" "VACUUM;" \
  && export USER_ID=1000 \
  && docker run -it \
    --env USER_ID="$USER_ID" \
    --publish 3001:3001/tcp \
    --volume "$(pwd)/storage/index/lib":"/var/lib/torrust/index" \
    --volume "$(pwd)/storage/index/log":"/var/log/torrust/index" \
    --volume "$(pwd)/storage/index/etc":"/etc/torrust/index" \
    torrust/index:develop
josecelano commented 1 month ago

We have to update the docs: https://docs.rs/torrust-index/3.0.0-rc.1/torrust_index/#run-with-docker