onlyrickroll commited on
Commit
f0270c8
·
verified ·
1 Parent(s): 3c84c90

Upload Dockerfile-alpine.txt

Browse files
Files changed (1) hide show
  1. Dockerfile-alpine.txt +68 -0
Dockerfile-alpine.txt ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nginx:alpine
2
+
3
+ # 安装依赖:SSH、Nginx、Cloudflared、bash
4
+ RUN apk add --no-cache openssh bash curl && \
5
+ # 设置 root 密码
6
+ echo "root:123456" | chpasswd && \
7
+ sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config && \
8
+ sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
9
+ sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
10
+ # 核心修改:关闭严格模式
11
+ echo "StrictModes no" >> /etc/ssh/sshd_config && \
12
+ # 创建必要目录
13
+ mkdir -p /var/run/sshd /run/nginx /etc/cloudflared && \
14
+ # 生成 SSH host keys
15
+ ssh-keygen -A && \
16
+ rm -rf /var/cache/apk/*
17
+ #touch /etc/nginx/nginx.conf
18
+
19
+ # 复制 Nginx 配置
20
+ #COPY nginx.conf /etc/nginx/nginx.conf
21
+ # 5. 覆盖默认配置,监听 7860 端口
22
+ # 注意:非 root 用户无法监听 1024 以下的端口(如 80),但可以监听 7860
23
+ RUN echo 'server { \
24
+ listen 7860; \
25
+ server_name localhost; \
26
+ location / { \
27
+ root /usr/share/nginx/html; \
28
+ index index.html index.htm; \
29
+ try_files $uri $uri/ /index.html; \
30
+ } \
31
+ }' > /etc/nginx/conf.d/default.conf
32
+ # 复制 Cloudflared 配置
33
+ # 2. 安装 Cloudflare Tunnel
34
+ RUN curl -L --output /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && \
35
+ chmod +x /usr/local/bin/cloudflared
36
+ #COPY config.yml /etc/cloudflared/config.yml
37
+
38
+ # 启动脚本
39
+ #COPY start.sh /start.sh
40
+ #RUN chmod +x /start.sh
41
+
42
+ # 暴露端口(容器内)
43
+
44
+
45
+ RUN adduser -D -u 1000 user && \
46
+ echo "user:hf123" | chpasswd
47
+
48
+ # 4. 目录授权 (关键步骤)
49
+ RUN mkdir -p /var/run/sshd /app/.cloudflared && \
50
+ chown -R user:user /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx /var/run/sshd /etc/ssh /var/run /app && \
51
+ touch /var/run/nginx.pid && \
52
+ chown user:user /var/run/nginx.pid
53
+
54
+ RUN chmod 4755 /bin/busybox && chmod 644 /etc/shadow
55
+
56
+ # 暴露 7860 (Web) 和 2222 (SSH)
57
+ EXPOSE 7860 2222
58
+ # 3. 切换到非 root 用户
59
+ USER user
60
+ WORKDIR /app
61
+
62
+ # 复制并设置 entrypoint 脚本
63
+ COPY --chown=user entrypoint.sh /app/entrypoint.sh
64
+ RUN chmod +x /app/entrypoint.sh
65
+ #CMD sh -c "#/usr/sbin/sshd && \ nginx -g 'daemon off;'"
66
+ #CMD /usr/sbin/sshd && nginx -g "daemon off;"
67
+ #CMD ["nginx", "-g", "daemon off;"]
68
+ CMD ["/app/entrypoint.sh"]