sam-fritz commited on
Commit
b59e674
·
verified ·
1 Parent(s): c3f8e65

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -18
Dockerfile CHANGED
@@ -1,48 +1,59 @@
1
  FROM mintplexlabs/anythingllm:latest
2
 
3
- # Switch to root to configure the startup script
4
  USER root
5
 
6
- # Setup the Hotdir (Ephemeral processing folder)
7
- # We do this at build time because this lives in the container, not the persistent drive.
8
  RUN mkdir -p /collector/hotdir && \
9
  chmod -R 777 /collector && \
10
  chown -R 1000:1000 /collector
11
 
12
- # Create a custom startup script
13
- # This script runs at BOOT, so it can see the persistent drive.
 
14
  RUN echo '#!/bin/bash\n\
15
  \n\
16
- # 1. Ensure the persistent storage directory exists on the mounted drive\n\
 
 
17
  if [ ! -d "/data/storage" ]; then\n\
18
- echo "Creating persistent storage directory..."\n\
19
  mkdir -p /data/storage\n\
20
  fi\n\
21
  \n\
22
- # 2. Fix permissions on the persistent drive so the app user can write to it\n\
23
- echo "Fixing permissions..."\n\
 
24
  chown -R 1000:1000 /data\n\
25
  chmod -R 777 /data\n\
26
  \n\
27
- # 3. Export critical variables to force the app to use this path\n\
 
 
 
 
 
28
  export STORAGE_DIR="/data/storage"\n\
29
  export DATABASE_URL="file:/data/storage/anythingllm.db"\n\
30
  \n\
31
- # 4. Start the main application\n\
32
- echo "Starting AnythingLLM..."\n\
33
- exec /usr/local/bin/docker-entrypoint.sh composer start\n\
 
34
  ' > /start.sh && chmod +x /start.sh
35
 
36
- # Set environment variables for the image as well (redundancy is good)
37
  ENV SERVER_PORT=7860
38
  ENV STORAGE_DIR="/data/storage"
39
  ENV DATABASE_URL="file:/data/storage/anythingllm.db"
40
 
41
- # Expose the port
42
  EXPOSE 7860
43
 
44
- # Switch back to the application user
45
- USER 1000
 
46
 
47
- # Use our custom script as the entrypoint command
48
  CMD ["/start.sh"]
 
1
  FROM mintplexlabs/anythingllm:latest
2
 
3
+ # Switch to root to ensure we can create scripts and directories
4
  USER root
5
 
6
+ # 1. Setup the ephemeral "hotdir" for the collector
7
+ # We create it now to ensure it exists.
8
  RUN mkdir -p /collector/hotdir && \
9
  chmod -R 777 /collector && \
10
  chown -R 1000:1000 /collector
11
 
12
+ # 2. Create the startup script
13
+ # IMPORTANT: This script will run as ROOT to fix permissions,
14
+ # then step down to user 1000 to run the app.
15
  RUN echo '#!/bin/bash\n\
16
  \n\
17
+ echo "--- Starting System Setup ---"\n\
18
+ \n\
19
+ # 1. Ensure Persistent Storage exists\n\
20
  if [ ! -d "/data/storage" ]; then\n\
21
+ echo "Creating /data/storage..."\n\
22
  mkdir -p /data/storage\n\
23
  fi\n\
24
  \n\
25
+ # 2. Force Permissions on Persistent Storage (As Root)\n\
26
+ # This ensures User 1000 can write to the mounted drive\n\
27
+ echo "Fixing permissions on /data..."\n\
28
  chown -R 1000:1000 /data\n\
29
  chmod -R 777 /data\n\
30
  \n\
31
+ # 3. Ensure Collector Hotdir is writable\n\
32
+ echo "Fixing permissions on /collector..."\n\
33
+ chown -R 1000:1000 /collector\n\
34
+ chmod -R 777 /collector\n\
35
+ \n\
36
+ # 4. Define Environment Variables for the App\n\
37
  export STORAGE_DIR="/data/storage"\n\
38
  export DATABASE_URL="file:/data/storage/anythingllm.db"\n\
39
  \n\
40
+ # 5. Start the App as User 1000 (app user)\n\
41
+ # We use "su" to switch from root to user 1000 while preserving the environment\n\
42
+ echo "Starting AnythingLLM as user 1000..."\n\
43
+ exec su -p -s /bin/bash 1000 -c "/usr/local/bin/docker-entrypoint.sh composer start"\n\
44
  ' > /start.sh && chmod +x /start.sh
45
 
46
+ # Set environment variables
47
  ENV SERVER_PORT=7860
48
  ENV STORAGE_DIR="/data/storage"
49
  ENV DATABASE_URL="file:/data/storage/anythingllm.db"
50
 
51
+ # Expose port
52
  EXPOSE 7860
53
 
54
+ # CRITICAL CHANGE: We stay as ROOT here so the CMD can run with permissions.
55
+ # The script itself handles switching down to user 1000.
56
+ USER root
57
 
58
+ # Start via our script
59
  CMD ["/start.sh"]