HongShi418 commited on
Commit
fdcdcb2
·
verified ·
1 Parent(s): 2121280

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +75 -0
Dockerfile ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:22.04
2
+
3
+ # Install necessary tools
4
+ RUN apt-get update && apt-get install -y \
5
+ tar \
6
+ gzip \
7
+ file \
8
+ jq \
9
+ curl \
10
+ sed \
11
+ aria2 \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Set up a new user named "user" with user ID 1000
15
+ RUN useradd -m -u 1000 user
16
+
17
+ # Switch to the "user" user
18
+ USER user
19
+
20
+ # Set home to the user's home directory
21
+ ENV HOME=/home/user \
22
+ PATH=/home/user/.local/bin:$PATH
23
+
24
+ # Set the working directory to the user's home directory
25
+ WORKDIR $HOME/openlist
26
+
27
+ # Download the latest OpenList release using jq for robustness
28
+ RUN curl -sL https://api.github.com/repos/openlistteam/openlist/releases/latest | \
29
+ jq -r '.assets[] | select(.name | test("linux-amd64.tar.gz$")) | .browser_download_url' | \
30
+ xargs curl -L | tar -zxvf - -C $HOME/openlist
31
+
32
+ # Set up the environment
33
+ RUN chmod +x $HOME/openlist/openlist && \
34
+ mkdir -p $HOME/openlist/data
35
+
36
+ # Create data/config.json file with database configuration
37
+ RUN echo '{\
38
+ "force": false,\
39
+ "address": "0.0.0.0",\
40
+ "port": 5244,\
41
+ "scheme": {\
42
+ "https": false,\
43
+ "cert_file": "",\
44
+ "key_file": ""\
45
+ },\
46
+ "cache": {\
47
+ "expiration": 60,\
48
+ "cleanup_interval": 120\
49
+ },\
50
+ "database": {\
51
+ "type": "mysql",\
52
+ "host": "ENV_MYSQL_HOST",\
53
+ "port": 3306,\
54
+ "user": "ENV_MYSQL_USER",\
55
+ "password": "ENV_MYSQL_PASSWORD",\
56
+ "name": "ENV_MYSQL_DATABASE"\
57
+ }\
58
+ }' > $HOME/openlist/data/config.json
59
+
60
+ # Create a startup script that runs OpenList and Aria2
61
+ RUN echo '#!/bin/bash\n\
62
+ sed -i "s/ENV_MYSQL_HOST/${MYSQL_HOST:-localhost}/g" $HOME/openlist/data/config.json\n\
63
+ sed -i "s/ENV_MYSQL_PORT/${MYSQL_PORT:-3306}/g" $HOME/openlist/data/config.json\n\
64
+ sed -i "s/ENV_MYSQL_USER/${MYSQL_USER:-root}/g" $HOME/openlist/data/config.json\n\
65
+ sed -i "s/ENV_MYSQL_PASSWORD/${MYSQL_PASSWORD:-password}/g" $HOME/openlist/data/config.json\n\
66
+ sed -i "s/ENV_MYSQL_DATABASE/${MYSQL_DATABASE:-openlist}/g" $HOME/openlist/data/config.json\n\
67
+ aria2c --enable-rpc --rpc-listen-all --rpc-allow-origin-all --rpc-listen-port=6800 --daemon\n\
68
+ $HOME/openlist/openlist server --data $HOME/openlist/data' > $HOME/openlist/start.sh && \
69
+ chmod +x $HOME/openlist/start.sh
70
+
71
+ # Set the command to run when the container starts
72
+ CMD ["/bin/bash", "-c", "/home/user/openlist/start.sh"]
73
+
74
+ # Expose the default OpenList port
75
+ EXPOSE 5244 6800