File size: 2,407 Bytes
97aaffe
f0270c8
 
97aaffe
f0270c8
 
 
 
 
 
 
 
 
 
 
97aaffe
f0270c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97aaffe
f0270c8
 
 
 
97aaffe
f0270c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
FROM node:slim

# 安装依赖:SSH、Nginx、Cloudflared、bash
RUN apt install --no-cache openssh bash curl nginx && \
    # 设置 root 密码
    echo "root:123456" | chpasswd && \
    sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
    # 核心修改:关闭严格模式
    echo "StrictModes no" >> /etc/ssh/sshd_config && \
    # 创建必要目录
    mkdir -p /var/run/sshd /run/nginx /etc/cloudflared && \
    # 生成 SSH host keys
    ssh-keygen -A && \
    rm -rf /var/cache/apt/*
    #touch /etc/nginx/nginx.conf

# 复制 Nginx 配置
#COPY nginx.conf /etc/nginx/nginx.conf
# 5. 覆盖默认配置,监听 7860 端口
# 注意:非 root 用户无法监听 1024 以下的端口(如 80),但可以监听 7860
RUN echo 'server { \
    listen 7860; \
    server_name localhost; \
    location / { \
        root /usr/share/nginx/html; \
        index index.html index.htm; \
        try_files $uri $uri/ /index.html; \
    } \
}' > /etc/nginx/conf.d/default.conf
# 复制 Cloudflared 配置
# 2. 安装 Cloudflare Tunnel
RUN curl -L --output /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && \
    chmod +x /usr/local/bin/cloudflared
#COPY config.yml /etc/cloudflared/config.yml

# 启动脚本
#COPY start.sh /start.sh
#RUN chmod +x /start.sh
RUN npm install -g openclaw@latest

# 暴露端口(容器内)


RUN useradd -D -u 1000 user && \
    echo "user:hf123" | chpasswd

# 4. 目录授权 (关键步骤)
RUN mkdir -p /var/run/sshd /app/.cloudflared && \
    chown -R user:user /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx /var/run/sshd /etc/ssh /var/run /app && \
    touch /var/run/nginx.pid && \
    chown user:user /var/run/nginx.pid

RUN chmod 4755 /bin/busybox && chmod 644 /etc/shadow   

# 暴露 7860 (Web) 和 2222 (SSH)
EXPOSE 7860 2222
# 3. 切换到非 root 用户
USER user
WORKDIR /app

# 复制并设置 entrypoint 脚本
COPY --chown=user entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
#CMD sh -c "#/usr/sbin/sshd && \ nginx -g 'daemon off;'"
#CMD /usr/sbin/sshd && nginx -g "daemon off;"
#CMD ["nginx", "-g", "daemon off;"]
CMD ["/app/entrypoint.sh"]