docker-entrypoint.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # Get the PUID and PGID from environment variables (or use default values 1000 if not set)
  3. PUID=${PUID:-1000}
  4. PGID=${PGID:-1000}
  5. # Check if the provided PUID and PGID are non-empty, numeric values; otherwise, assign default values.
  6. if ! [[ "$PUID" =~ ^[0-9]+$ ]]; then
  7. PUID=1000
  8. fi
  9. if ! [[ "$PGID" =~ ^[0-9]+$ ]]; then
  10. PGID=1000
  11. fi
  12. # Check if the specified group with PGID exists, if not, create it.
  13. if ! getent group "$PGID" >/dev/null; then
  14. groupadd -g "$PGID" appgroup
  15. fi
  16. # Create user.
  17. useradd --create-home --shell /bin/bash --uid "$PUID" --gid "$PGID" appuser
  18. # Make user the owner of the app directory.
  19. chown -R appuser:appgroup /app
  20. # Copy the default .bashrc file to the appuser home directory.
  21. cp /etc/skel/.bashrc /home/appuser/.bashrc
  22. chown appuser:appgroup /home/appuser/.bashrc
  23. export HOME=/home/appuser
  24. # Set permissions on font directories.
  25. if [ -d "/usr/share/fonts" ]; then
  26. chmod -R 777 /usr/share/fonts
  27. fi
  28. if [ -d "/var/cache/fontconfig" ]; then
  29. chmod -R 777 /var/cache/fontconfig
  30. fi
  31. if [ -d "/usr/local/share/fonts" ]; then
  32. chmod -R 777 /usr/local/share/fonts
  33. fi
  34. # Switch to appuser and execute the Docker CMD or passed in command-line arguments.
  35. # Using setpriv let's it run as PID 1 which is required for proper signal handling (similar to gosu/su-exec).
  36. exec setpriv --reuid=$PUID --regid=$PGID --init-groups $@